博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle:Authid Current_User使用
阅读量:6691 次
发布时间:2019-06-25

本文共 2238 字,大约阅读时间需要 7 分钟。

    由于用户拥有的role权限在存储过程是不可用的。遇到这种情况,我们一般需要显示授权,如grant create table to user;但这种方法太麻烦,有时候可能需要进行非常多的授权才能执行存储过程,实际上,oracle给我们提供了在存储过程中使用role权限的方法:修改存储过程,加入Authid Current_User时存储过程可以使用role权限。

    下面以例子说明:

----执行存储过程p_create_emp2报下面的错误:SQL> exec p_create_emp2; begin p_create_emp2; end; ORA-01031: 权限不足ORA-06512: 在 "ECHO.P_CREATE_EMP2", line 12ORA-06512: 在 line 2----查看p_create_emp2,该存储过程是要创建emp2表create or replace procedure P_create_emp2 as  cursor t_cursor is  select * from user_tables where table_name = 'EMP2';  t_cur t_cursor%rowtype;  num int:=0;begin  for t_cur in t_cursor loop   num:=num+1;  end loop;  if num=1 then    execute immediate 'drop table emp2 purge';    execute immediate 'create table emp2 as select * from emp';  else    execute immediate 'create table emp2 as select * from emp';  end if;end P_create_emp2;----查看echo用户的角色或权限SQL> select * from dba_role_privs where grantee='ECHO'; GRANTEE                        GRANTED_ROLE                   ADMIN_OPTION DEFAULT_ROLE------------------------------ ------------------------------ ------------ ------------ECHO                           DBA                            NO           YES----有dba的角色,说明建表的权限----修改存储过程p_create_emp2:create or replace procedure P_create_emp2 authid current_user as  cursor t_cursor is  select * from user_tables where table_name = 'EMP2';  t_cur t_cursor%rowtype;  num int:=0;begin  for t_cur in t_cursor loop   num:=num+1;  end loop;  if num=1 then    execute immediate 'drop table emp2 purge';    execute immediate 'create table emp2 as select * from emp';  else    execute immediate 'create table emp2 as select * from emp';  end if;end P_create_emp2;----再次执行:SQL> exec p_create_emp2; PL/SQL procedure successfully completed SQL> desc emp2;Name     Type         Nullable Default Comments -------- ------------ -------- ------- -------- EMPNO    NUMBER(4)    Y                         ENAME    VARCHAR2(10) Y                         JOB      VARCHAR2(9)  Y                         MGR      NUMBER(4)    Y                         HIREDATE DATE         Y                         SAL      NUMBER(7,2)  Y                         COMM     NUMBER(7,2)  Y                         DEPTNO   NUMBER(2)    Y                ----在存储过程加了Authid Current_User选项,表创建成功。

 

转载地址:http://rvhao.baihongyu.com/

你可能感兴趣的文章
针对IE6\7\8\9\10浏览器的CSS hack大全详解
查看>>
C++应用程序性能优化(二)——C++对象模型
查看>>
smarty 中一些方法的使用
查看>>
大型网站技术架构(五)网站高可用架构
查看>>
Maven学习总结(五)——聚合与继承
查看>>
LNMP架构 源码安装nginx+mysql+php+memcache+论坛
查看>>
Linux实用工具
查看>>
Spring学习总结(4)——Spring AOP教程
查看>>
通过JDBC向数据库中存储&读取Blob数据
查看>>
将博客搬至51CTO
查看>>
C++11: CAS
查看>>
我的友情链接
查看>>
pfSense book之证书管理
查看>>
博客开张
查看>>
jquery.Callbacks的实现
查看>>
同一环境下新建Standby RAC库
查看>>
随手笔记NO.4
查看>>
未来监护人:FCC专员正在努力推迟网络中立投票
查看>>
LVS负载均衡群集(LVS-NAT)
查看>>
【Zabbix】如何搭建memcached?并使用Zabbix监控memcached?
查看>>