Insufficient permissions for dynamic SQL statements in Stored Procedures

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.