1.cmd->sqlplus /as sysdba--无密码登录 2.conn sys /svse@orcl as sysdba--管理员登录 3.conn scott/tiger--用户登录 alter user jacob account unlock;--解除锁定 alter user jacob identified by king; 4.set linesize 500 --每行多少记录 set pagesize 100 --每页多少数据 selectfrom emp;=run=r=/ 5.alter session set NLS_date_format='YYYY-MM-DD'--格式化日期 6.insert into emp(empno,ename,sal)values(&employeeno,'&employeename', &employeesal);--多次添加数据 7. 从其他表中复制数据 用查询结果创建新表 Insert语句中使用子查询 insert into managers(id,name,salary,hiredate)select empno,ename,sal,hiredate from emp where job='manager'; 8.必须commit或rooback数据操作才能生效 9.select ename||' '||'is a'||job from emp;--字符串拼接 10.select distinct deptno from emp;--distinct消除重复数据行 11.select empno ,ename from emp order by empno asc;--升序排列 12. select empno ,ename from emp order by empno desc;--降序排列 13.set timing on;--设置执行所用时间 14.insert into stuinfo(stuid,stuname) selectfrom stuinfo ;--疯狂赋值 15. selectfrom (select a1.,rownum rn from (selectfrom emp order by sal desc) a1 where rownum<9) where rn>=4;--rownum分页查询 16.select ename,sal,job from emp where sal>2500 union select ename,sal,job from emp where job='Manager';--union联合查询 17.update emp set(job,sal,comm)=(select job,sal,comm from emp where ename='smith') where ename='scott';--更新员scott的岗位,工资,补助与smith员工一致(使用update语句更新数据时,既可以使用表达式或者数值直接修改数据,也可以使用子查询修改数据) 18。字符函数 lowe(char);upper(char);length(char);substr(char,startposition,num); 19.select upper (substr(ename,1,1)) ||lower(substr(ename,2,length(ename)-1)) from emp;--首字母大写 20.select replace(ename,'a','X') from emp;--将ename下的a字符替换为X 21.select round(sal,1) from emp;--四舍五入一位小数 22.select trunc(comm,1) from emp;--截取一位小数 23.select floor(comm) from emp;--返回大于或是等于n的最大整数 24.select ceil(comm) from emp;--返回大于或是等于comm的最大整数 25.select ename,to_char(hiredate,'yyyy-mm-dd hh24:mi:ss') from emp;--查询时间精确到秒 26.如何查询一个角色包括的权限? a。一个角色包含的系统权限 selectfrom dba_sys_privs where grantee="CONNECT"; 另外也可以这样查看: selectfrom role_sys_privs where role="CONNECT"; b.一个角色包含的对象权限 selectfrom dba_tab_privs where grantee="CONNECT"; 27.oracle究竟有多少种角色? selectfrom dba_roles; 28.如何查看某个用户,具有什么样的角色? selectfrom dba_role_privs where grantee="用户名"; 29.查看当前所用数据库的全称 selectfrom global_name; 30.表空间介绍及用途: 表空间用于从逻辑上组织数据库的数据,数据库逻辑上是由一个或多个表空间组成的。通过表空间可以达到以下作用: a.控制数据库占用的磁盘空间。 b.dba可以将不同数据类型部署到不同的位置,这样有利于提高I/O性能,同时利于备份和恢复等管理操作。 31.添加不为空的约束 alter table stuinfo modify stuname not null; 32.添加约束 alter table stuinfo add constraint card_unique【约束名(自定义)】 unique(stuname); 33.添加年龄约束 alter table stuinfo add constraint stuage_check check(stuage between 1 and 100); 34.添加地址约束 alter table stuinfo add constraint address_checkcheck (address in('上海','深圳')); 35.删除约束 alter table 表名 drop primary key; 36.如果两张表存在主从关系,那么在删除主表约束时,必须带上cascade选项 alter table 表名 drop primary key cascade【级联】; 37.查询约束信息 a.显示约束信息 select constraint_name,constraint_type,status,validated from user_constraints where table_name="表名"; b.显示约束列 select column_name,position from user_cons_columns where constraint_name='约束名'; c.辅助工具查看 38.创建单列索引【基于单个列创建的索引】 create index 索引名 on 表名(列名); 39.复合索引【基于两列或多列的索引,在同一张表上可以创建多个索引,但是要求列的组合必须不同】 create index emp_index1 on emp(ename,job); create index emp_index1 on emp(job,ename); 40.创建用户 create user jacob idnetified by king; 41.授权用户jacob建表权限 grant create session,create table to jacob with admin option; 42.回收用户权限【jacob赋予king权限】 revoke【撤销】 create session from king;【回收king后jaocb依然可以使用,非级联撤销】 43.只可修改表的一个字段 grant update on emp(sal) to jaocb; 44.只可查询几个字段 grant select on emp(ename,sal) to jacob; 45.回收对象权限【scott->jacob->king】(scott删除jacob的权限后king就不能做相应操作了) 46.oracle分页原理 a.select t1.,rownum rn from (selectfrom emp) t1; b.select t1.,rownum rn from (selectfrom emp) t1 where rownum<=10; c.selectfrom (select t1.,rownum rn from (selectfrom emp) t1 where rownum<=10) where rn>=6; 47.创建序列 create sequence S_SYS increment by 1
start with 1 ;
48.授权jacob查看所有表 grant select any table to jacob ; 49.递归查询子部门 SELECT T.* FROM SYSP.T_ORGANIZATION T START WITH 1=1 CONNECT BY T.PARENTID = PRIOR T.ID where T.id="1000"
--------------------------------***********----------------------------------------------------- --1.建表空间 create tablespace jzrsDB datafile 'c:\oracle\jzrsDB.ora' size 100m reuse default storage(initial 500k next 500k pctincrease 20); --2.建用户 create user jzrsoa identified by jzrsoa; --identified by后面的是密码,前面的是用户名 --3.用户授权 grant resource,connect,RECOVERY_CATALOG_OWNER to jzrsoa ; grant create table to jzrsoa ; alter user jzrsoa quota unlimited ON jzrsDB; alter user jzrsoa default tablespace jzrsDB; ----查看锁表 select p.spid,c.object_name,b.session_id,b.oracle_username,b.os_user_name
from v$process p,v$session a, v$locked_object b,all_objects c
where p.addr=a.paddr and a.process=b.process and c.object_id=b.object_id
----解锁 alter system kill session '锁表ID' ---Hacker cmd 1 当前用户权限 (select * from session_roles) 2 当前数据库版本 (select banner from sys.v_$version where rownum=1) 3 服务器出口IP (用utl_http.request可以实现) 4 服务器监听IP (select utl_inaddr.get_host_address from dual) 5 服务器操作系统 (select member from v$logfile where rownum=1) 6 服务器sid (远程连接的话需要,select instance_name from v$instance;) 7 当前连接用户 (select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual)
oracle导出dmp文件命令 exp system/oracle@RDSADEV file=e:\ps.dmp owner=(project,sysp)
oracle导入dmp文件命令 1.首先进入cmd命令窗口 2.执行命令: /* 用户名:就是你的目标用户 。 密码:就是你的目标用户登录密码。 orcl:是实例名称 就是数据库名。 file:就是你要导入的dmp文件全路径。 full=y 是否全部导入只有当前用户是dba的时候才能用此选项 。 */ imp userid=system/oracle@orcl file=e:\project.dmp full=y