oracle小结1

来源:互联网 发布:茂名软件开发公司 编辑:程序博客网 时间:2024/05/01 18:46

1 显示操作时间
   set timing on;

2 nvl(comm,0),如果COMM为空,则显示0,否则用COMM显示
3  当  groupy,having,order by同时存在时,必须是先出现group by,然后
是having,最后是order by
4 select * from (select a1.*,rownum rn from (select * from scott.emp) a1 where rownum<=10) where rn>=6(不支持rownum

的2次使用)
  如果指定查询列,只需修改最底层的(select * from scott.emp)
 
5 insert into kkk (a,b,c) select a,b,c from emp;(即可适合大批量数据录入)

6 设置只读事务
  set transcation read only;则A设置了只读事务的话,则在设置后
的新的DML则无效果

 


7 导出表
   导出自己的表
   exp userid=scott/xxx@xxx tables=(a,b) file=c:/xxx.dmp;
导出其他的方案
   exp userid=system/xx@xxx tables=(scott.a,scott.b) file=c:/xxx.dmp
只导出表结构,不导数据
   exp userid=system/xx@xxx tables=(scott.a,scott.b) file=c:/xxx.dmp rows=n;
   如果要导出大表,则加参数direct=y
导出方案
  exp userid=system/xx@xxx owner=(scott,system) file=c:/xxxx.dmp;
8 数据字典视图
  包括user_xxx,all_xxx,dba_xxx三类

9 查看用户的角色
 
select * from dba_role_privs where GRANTEE='SCOTT';

查看某个角色所包含的系统权限
  select * from dba_sys_privs where grantee='connect'
查看某个角色所包含的对象权限
  select * from dba_tab_privs where grantee='connect'
查看某个用户有多少角色
  select * from dba_role_privs where grantee='用户名';


10 分页的存储过程
 
create or replace package tespackage as
 type test_cursor is ref cursor;
end testpackage;

create or replace procedure fenye
(tableName in varchar2,
Pagesize in number,
pageNow in number,
myrows out number,总记录数
myPageCount out number 总页数
p_cursor out tespackage.test_cursor --返回的记录集
)
 is
v_sql varchar2(10000);
 
v_begin number:=(pageNow-1)*Pagesize+1;
v_end number:= pageNow*Pagesize;
begin
 v_sql:='select * from (select t1.*,rownum rn from (select * from '||tableName
||') t1 where rownum<='||v_end||') where rn>='||v_begin;
open p_cursor for v_sql;
--计算myrows和mypagecount
v_sql:='select count(*) from'||tableName;
execute immediate v_sql into myrows;
if mod(myrows,Pagesize)=0 then
  myPageCount:=myrows/Pagesize;
else
  myPageCount:=myrows/Pagesize+1;
end if;
close p_cursor;
end;

end;

原创粉丝点击