If the following stored procedure is executed under the System account, the error "create?" is returned? Procedure? ImmediateSQLbeginexecutiveimmediategrantselecton? Scott. empto? Infodata; end; beginimmediateSQL; end; but directly execute the following statement under SQLPlus without any problem: beginexecutiv
If the following stored procedure is executed under the System account, the error "create?" is returned? Procedure? ImmediateSQL begin executive immediate grant select on? Scott. emp? Infodata; end; begin immediateSQL; end; but directly execute the following statement in SQL Plus.
Insufficient permission error when executing the following stored procedure under the System Account
Create? Procedure? ImmediateSQL
Begin
Executive immediate 'Grant select on? Scott. emp? Infodata ';
End;
Begin
ImmediateSQL;
End;
However, it is no problem to directly execute the following statements under SQL Plus.
Begin
Executive immediate 'Grant select on? Scott. emp? Infodata ';
End;
There are two types of stored procedures: DR (Definer's Rights) Procedure and IR (Invoker's Rights) Procedure.
No problem after the following definition is executed
Create? Procedure? ImmediateSQL? AUTHID CURRENT_USER
Begin
Executive immediate 'Grant select on? Scott. emp? Infodata ';
End;
Name resolution environment of stored procedure execution permission
These two problems can be solved by specifying the AUTHID attribute when defining the stored Procedure, that is, defining DR Procedure and IR Procedure.
DR Procedure
1. Definition
Create or replace procedure DEMO (ID in NUMBER) authid definer
BEGIN
END;
2. The name resolution environment is the Schema of the user who defines the stored procedure.
3. Only the Public permission is allowed to execute the stored procedure.
IR Procedure
1. Definition
Create or replace procedure DEMO (ID in NUMBER) AUTHID CURRENT_USER
BEGIN
END;
2. The name resolution environment is the Schema of the user who calls the stored procedure.
3. When executing the stored procedure, all the permissions of the caller are granted, that is, the caller's Role is valid.
Original article address: insufficient permissions for dynamic SQL statements in the stored procedure. Thank you for sharing it with the original author.