Use of authid CURRENT_USER

Source: Internet
Author: User

We know that the role permissions of users are not available in the stored procedure. In this case, we usually need explicit authorization, such as grant create table to usera. However, this method is too troublesome. Sometimes a lot of authorization is required to execute the stored procedure. In fact, oracle provides us with a way to use the role permission in the stored procedure: Modify the stored procedure. When the authid CURRENT_USER is added, the stored procedure can use the role permission. The following is an example:
 
SQL> select * from V $ version;
Banner
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
PL/SQL release 10.2.0.1.0-Production
Core 10.2.0.1.0 Production
TNS for 32-bit windows: Version 10.2.0.1.0-Production
Nlsrtl version 10.2.0.1.0-Production
 
SQL> conn sjh/sjh
Connected.
SQL> Create or replace procedure p_test
2 is
3 begin
4 execute immediate 'create table creat_table (ID number )';
5 end;
6/
The process has been created.
 
SQL> exec p_test;
Begin p_test; end;
*
Row 3 has an error:
ORA-01031: insufficient Permissions
ORA-06512: In "sjh. p_test", line 4
ORA-06512: In line 1

SQL>
SQL> select * From dba_role_privs where grantee = 'sjh ';
Grantee granted_role ADM def
------------------------------------------------------------------
Sjh resource no Yes
 
-- In fact, the sjh user has the resource role, that is, the table creation permission.
 
SQL> select * From dba_role_privs where grantee = 'sfx ';
Grantee granted_role ADM def
------------------------------------------------------------------
SFX resource no Yes
SFX connect No Yes
SFX plustrace No Yes
 
SQL> Create or replace procedure p_test
2 authid CURRENT_USER
3 is
4 begin
5 execute immediate 'create table creat_table (ID number )';
6 end;
7/
The process has been created.
 
SQL> exec p_test;
The PL/SQL process is successfully completed.
 
SQL> select * From creat_table;
Unselected row
 
-- The authid CURRENT_USER option is added to the stored procedure. The table is successfully created.

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.