`

ORA-01031: insufficient privileges when run a procedure.

 
阅读更多

ORA-01031: insufficient privileges
Got the ORA error when I try to run a procedure.
There is create table SQL in the procedure.
This needs to be granted the privileges explicitly.
Just because The Roles are disabled inside stored procedures. For example, if the CREATE TABLE privilege is granted to you via a role, and you use the DBMS_SQL package to create a table, you will receive the Oracle error 'ORA-01031: insufficient privileges'.
The solution is to grant the required privileges to the owner of the subprogram.

The reason for this is, unlike other Oracle supplied packages, the dbms_sql package, when used inside a stored subprogram, executes with the privileges of the owner of the subprogram, and not with the privileges of the caller.

Oracle 8i introduces invoker-rights for named PL/SQL. Therefore, roles are enabled for procedures created with AUTHID CURRENT_USER (i.e. Oracle supplied packages DBMS_SQL and DBMS_SYS_SQL). Thus, in Oracle 8i, the required privilege(s) can either be granted directly to the user or to the user via a role, including PUBLIC. Since Oracle supplied packages (i.e. DBMS_SQL and DBMS_SYS_SQL) are created with invoker-rights in 8i,roles can be granted the associated privileges.

EG:

I output the SQL embeded in the procedure.

SQL> exec PROC_AM_MIG('ipaddress_type','ipaddress','ipaddress_type_id','ipaddress_type_id','ipaddress_id','sp_id','ipaddress_type')
CREATE TABLE ipaddress_type_temp as select * from (select
ipaddress_type_id,ipaddress_type, dense_rank() over ( partition by
ipaddress_type order by sp_id) as rank from ipaddress_type ) where rank = 1
CREATE TABLE ipaddress_temp as (select a.*,c.ipaddress_type_id
ipaddress_type_id_temp from ipaddress a inner join ipaddress_type b on
a.ipaddress_type_id=b.ipaddress_type_id inner join ipaddress_type_temp c on
c.ipaddress_type=b.ipaddress_type)
alter table ipaddress_temp set unused (ipaddress_type_id)
alter table ipaddress_temp rename column ipaddress_type_id_temp to
ipaddress_type_id
RENAME ipaddress_type TO ipaddress_type_bak
RENAME ipaddress_type_temp TO ipaddress_type
RENAME ipaddress TO ipaddress_bak
RENAME ipaddress_temp TO ipaddress
ALTER TABLE ipaddress_type ADD PRIMARY KEY (ipaddress_type_id)
ALTER TABLE ipaddress ADD FOREIGN KEY (ipaddress_type_id) REFERENCES
ipaddress_type (ipaddress_type_id )
ORA-01031: insufficient privileges

PL/SQL procedure successfully completed.
Thre is no change in the tables.
SQL> select * from ipaddress;

IPADDRESS_ID NAME IPADDRESS_TYPE_ID
------------ ---------- -----------------
1 a 1
2 b 2
3 v 3
4 n 1

SQL> select * from ipaddress_type;

IPADDRESS_TYPE_ID IPADDRESS_ SP_ID
----------------- ---------- ----------
1 typeA 1
2 typeB 2
3 typeA 3

SQL> grant create any table to public;

Grant succeeded.

SQL> exec PROC_AM_MIG('ipaddress_type','ipaddress','ipaddress_type_id','ipaddress_type_id','ipaddress_id','sp_id','ipaddress_type')
CREATE TABLE ipaddress_type_temp as select * from (select
ipaddress_type_id,ipaddress_type, dense_rank() over ( partition by
ipaddress_type order by sp_id) as rank from ipaddress_type ) where rank = 1
CREATE TABLE ipaddress_temp as (select a.*,c.ipaddress_type_id
ipaddress_type_id_temp from ipaddress a inner join ipaddress_type b on
a.ipaddress_type_id=b.ipaddress_type_id inner join ipaddress_type_temp c on
c.ipaddress_type=b.ipaddress_type)
alter table ipaddress_temp set unused (ipaddress_type_id)
alter table ipaddress_temp rename column ipaddress_type_id_temp to
ipaddress_type_id
RENAME ipaddress_type TO ipaddress_type_bak
RENAME ipaddress_type_temp TO ipaddress_type
RENAME ipaddress TO ipaddress_bak
RENAME ipaddress_temp TO ipaddress
ALTER TABLE ipaddress_type ADD PRIMARY KEY (ipaddress_type_id)
ALTER TABLE ipaddress ADD FOREIGN KEY (ipaddress_type_id) REFERENCES
ipaddress_type (ipaddress_type_id )

PL/SQL procedure successfully completed.

SQL> select * from ipaddress;

IPADDRESS_ID NAME IPADDRESS_TYPE_ID
------------ ---------- -----------------
4 n 1
3 v 1
1 a 1
2 b 2

SQL> select * from ipaddress_type;

IPADDRESS_TYPE_ID IPADDRESS_ RANK
----------------- ---------- ----------
1 typeA 1
2 typeB 1

分享到:
评论

相关推荐

    ORA-01031 insufficient privilege

    sqlplus / as sysdba时出现ORA-01031 insufficient privilege

    ora-01031禁止操作系统集成的身份验证方式

    使用conn / as sysdba进入数据库,报错ORA-01031: insufficient privileges

    远程登录并启动oracle数据库 解决ORA-01031

    本文将详细介绍如何实现这一过程,并针对“ORA-01031: insufficient privileges”这一常见错误提供解决方案。 #### Oracle数据库远程连接认证方式 在Oracle数据库中,远程连接主要有两种认证方式: 1. **操作系统...

    ora-01033:oracle initialization or shutdown in progress 解决方法

    ### ora-01033: Oracle Initialization or Shutdown in Progress 解决方法 #### 一、问题背景及原因 **标题**: “ora-01033: Oracle initialization or shutdown in progress 解决方法” **描述**: “ora-01033: ...

    WMSYS.zip解决ORA-00904:

    -- 解决ORA-00904: "WMSYS"."WM_CONCAT": 标识符无效 的文件包....... -- 解决ORA-00904: "WMSYS"."WM_CONCAT": 标识符无效 的文件包....... -- 解决ORA-00904: "WMSYS"."WM_CONCAT": 标识符无效 的文件包....... ...

    如何处理错误ORA-29275:部分多字节字符

    ### 如何处理错误ORA-29275:部分多字节字符 #### 问题背景与描述 在Oracle数据库操作过程中,用户可能会遇到一个特定的错误提示——ORA-29275:部分多字节字符。这一错误通常出现在执行查询`SELECT * FROM V$...

    ORA-04052p5731178_92080_WINNT.zip

    ORA-00604: 递归SQL层1出现错误 ORA-03106: 致命的双工通信协议错误 ORA-02063: 紧接着line(源于dblink) 以及 ORA-04052: 在查找远程对象时出错 ORA-00604: 递归SQL层1出现错误 ORA-03120: 双工转换例行程序:整数...

    Oracle 授权 ORA-00990: 权限缺失或无效

    在Oracle数据库管理中,"ORA-00990: 权限缺失或无效"是一个常见的错误代码,它表示用户尝试执行的操作没有足够的权限。这个错误通常发生在试图访问、修改或者管理数据库对象(如表、视图、索引等)时。在本篇文章中...

    ORA-32001:请求写入spfile,但没有使用spfile的解决方法

    ORA-32001:write to spfile requested but no spfile is in use请求写入spfile,但没有使用spfile的解决方法 在输入以下语句中报了这样的错误: SQL>alter system set control_files=’/u01/app/oracle/oradata/prod/...

    ORA-12154: TNS: 无法解析指定的连接标识符的解决方法

    ORA-12154: TNS: 无法解析指定的连接标识符的解决方法

    Oracle错误码大全

    ORA-00001: 违反唯一约束条件 (.) ORA-00017: 请求会话以设置跟踪事件 ORA-00018: 超出最大会话数 ORA-00019: 超出最大会话许可数 ORA-00020: 超出最大进程数 () ORA-00021: 会话附属于其它某些进程;无法转换...

    ORA-00904: "WM_CONCAT": 标识符无效

    在Oracle数据库中,"ORA-00904"是一个常见的错误代码,它表示尝试引用一个不存在或无效的标识符。在这个场景下,错误信息提到的是"WM_CONCAT"函数,这表明在Oracle 19c数据库环境中,用户尝试使用WM_CONCAT函数,但...

    ORA-00060: 等待资源时检测到死锁--oracle 数据库表死锁异常

    在Oracle数据库系统中,"ORA-00060: 等待资源时检测到死锁" 是一个常见的错误提示,它表明两个或多个事务在执行过程中陷入了无法继续进行的状态,因为彼此都在等待对方释放资源。这种情况通常发生在并发操作中,比如...

    ORA-27101: shared memory realm does not exist.

    NULL 博文链接:https://snowelf.iteye.com/blog/507976

    oracle特有的错误:ORA-01036:非法的变量名/编号

    在Oracle数据库系统中,"ORA-01036:非法的变量名/编号"是一个常见的错误,通常出现在PL/SQL代码或者SQL查询语句中,当你尝试使用一个不正确或者未定义的变量时,Oracle数据库会抛出这个错误。这个错误可能是由于...

    oracle报错大全(珍藏版)

    #### ORA-00054: Resource Not Acquired When Waited 在等待时未能获得资源。这可能是因为资源被其他用户占用或并发控制机制的问题。 #### ORA-00055: Data Manipulation Language (DML) Operations 执行DML操作时...

    oracle12c ORA-01017: 用户名/口令无效; 登录被拒绝 解决方案

    oracle12c程序连接时异常: ORA-01017: 用户名/口令无效; 登录被拒绝 的解决方案。

    plsql常见问题.docx

    本文将详细解析"ORA-0131: Insufficient privileges"错误,并提供解决方案,同时也会介绍如何在PL/SQL Developer中导入SQL脚本。 1. ORA-0131 错误解析: 当你在PL/SQL Developer尝试调试存储过程时,如果收到...

    CLOB 字段类型报错 ORA-01704: 文字字符串过长的解决

    然而,当你尝试向CLOB字段插入数据时,如果超过了Oracle规定的最大限制,就会遇到“ORA-01704: 文字字符串过长”的错误。这个错误通常意味着你试图插入的字符串超过了Oracle数据库允许的最大长度,对于VARCHAR2类型...

Global site tag (gtag.js) - Google Analytics