AUTHID DEFINER\authid current_user與alter session set current_schema
先看看Tom上的一個例子:
ops$tkyte@ORA817DEV.US.ORACLE.COM> begin
2 execute immediate 'alter session set current_schema=scott';
3 for x in ( select sys_context('userenv','current_schema') x from dual )
4 loop
5 dbms_output.put_line( x.x );
6 end loop;
7
8
9 execute immediate 'alter session set current_schema=ops$tkyte';
10 for x in ( select sys_context('userenv','current_schema') x from dual )
11 loop
12 dbms_output.put_line( x.x );
13 end loop;
14 end;
15 /
SCOTT
OPS$TKYTE
PL/SQL procedure successfully completed.
2 execute immediate 'alter session set current_schema=scott';
3 for x in ( select sys_context('userenv','current_schema') x from dual )
4 loop
5 dbms_output.put_line( x.x );
6 end loop;
7
8
9 execute immediate 'alter session set current_schema=ops$tkyte';
10 for x in ( select sys_context('userenv','current_schema') x from dual )
11 loop
12 dbms_output.put_line( x.x );
13 end loop;
14 end;
15 /
SCOTT
OPS$TKYTE
PL/SQL procedure successfully completed.
Now, if your "block of code" is actually a stored procedure and it is further a
DEFINERS RIGHTS procedure (the default kind) then expect this (logged in as ops$tkyte by
the way):
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace procedure p
2 as
3 begin
4 execute immediate 'alter session set current_schema=scott';
5 for x in ( select sys_context('userenv','current_schema') x from dual )
6 loop
7 dbms_output.put_line( x.x );
8 end loop;
9
10
11 execute immediate 'alter session set current_schema=ops$tkyte';
12 for x in ( select sys_context('userenv','current_schema') x from dual )
13 loop
14 dbms_output.put_line( x.x );
15 end loop;
16 end;
17 /
Procedure created.
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec p
OPS$TKYTE
OPS$TKYTE
PL/SQL procedure successfully completed.
you cannot change your identity in a definers rights procedure, it is fixed AT COMPILE time by definition (if you have my book "expert one on one", read the chapter on invoker vs definer rights). Now, try this:
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace procedure p 2 AUTHID CURRENT_USER
3 as
4 begin
5 execute immediate 'alter session set current_schema=scott';
6 for x in ( select sys_context('userenv','current_schema') x from dual )
7 loop
8 dbms_output.put_line( x.x );
9 end loop;
10
11
12 execute immediate 'alter session set current_schema=ops$tkyte';
13 for x in ( select sys_context('userenv','current_schema') x from dual )
14 loop
15 dbms_output.put_line( x.x );
16 end loop;
17 end;
18 /
Procedure created.
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec p
SCOTT
OPS$TKYTE
PL/SQL procedure successfully completed.
可見對於DEFINERS RIGHTS procedure ,alter session set current_schema是無影響的;
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace procedure p
2 as
3 begin
4 execute immediate 'alter session set current_schema=scott';
5 for x in ( select sys_context('userenv','current_schema') x from dual )
6 loop
7 dbms_output.put_line( x.x );
8 end loop;
9
10
11 execute immediate 'alter session set current_schema=ops$tkyte';
12 for x in ( select sys_context('userenv','current_schema') x from dual )
13 loop
14 dbms_output.put_line( x.x );
15 end loop;
16 end;
17 /
Procedure created.
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec p
OPS$TKYTE
OPS$TKYTE
PL/SQL procedure successfully completed.
you cannot change your identity in a definers rights procedure, it is fixed AT COMPILE time by definition (if you have my book "expert one on one", read the chapter on invoker vs definer rights). Now, try this:
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace procedure p 2 AUTHID CURRENT_USER
3 as
4 begin
5 execute immediate 'alter session set current_schema=scott';
6 for x in ( select sys_context('userenv','current_schema') x from dual )
7 loop
8 dbms_output.put_line( x.x );
9 end loop;
10
11
12 execute immediate 'alter session set current_schema=ops$tkyte';
13 for x in ( select sys_context('userenv','current_schema') x from dual )
14 loop
15 dbms_output.put_line( x.x );
16 end loop;
17 end;
18 /
Procedure created.
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec p
SCOTT
OPS$TKYTE
PL/SQL procedure successfully completed.
可見對於DEFINERS RIGHTS procedure ,alter session set current_schema是無影響的;
對於authid current_user procedure將改變操作物件為current_schema指定的物件,預設current_schema為當前的呼叫者即current_user.
附:
CURRENT_SCHEMA
Syntax:
CURRENT_SCHEMA = schema
The CURRENT_SCHEMA parameter changes the current schema of the session to the specified schema. Subsequent unqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement.
This setting offers a convenient way to perform. operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session.
Syntax:
CURRENT_SCHEMA = schema
The CURRENT_SCHEMA parameter changes the current schema of the session to the specified schema. Subsequent unqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement.
This setting offers a convenient way to perform. operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/195110/viewspace-749551/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle儲存過程中authid current_user和authid definerOracle儲存過程
- Oracle:Authid Current_User的使用(轉)Oracle
- 儲存過程許可權__Authid Current_User儲存過程
- ORACLE 儲存過程中的Authid Current_UserOracle儲存過程
- 使用 Authid Current_User 為呼叫者授權
- Oracle 定義者許可權與呼叫者許可權(AUTHID CURRENT_USER)Oracle
- alter session setSession
- ALTER SESSION SET EVENTSSession
- 使用alter session set current_schema=scott用explain plan for檢視scott使用者的sqlSessionAISQL
- alter session|system set eventsSession
- [PL/SQL]Something about authid for proceduresSQL
- alter session set events /Oracle跟蹤SessionOracle
- job中呼叫儲存過程,儲存過程使用AUTHID CURRENT_USER,還出現ORA-01031儲存過程
- alter session set events 'immediate trace name controlf level 8'Session
- alter session set events語句dump 控制檔案頭資訊示例Session
- [20120103] alter session set statistics_level = all;Session
- alter system kill sessionSession
- alter session set events語句dump REDO日誌檔案頭資訊示例Session
- 記一次ALTER SESSION SET hash_join_enabled specifies an obsolete parameterSession
- alter database和alter system和alter session的區別DatabaseSession
- 轉儲控制檔案時遇到的知識點:所有alter session set eventSession
- v$lock之alter table drop column與alter table set unused column區別系列五
- alter system set event和set events的區別
- oracle10g_alter session set events 'immediate trace name controlf level 8'dumpOracleSession
- ALTER SESSION ADVISE ClauseSession
- ALTER SYSTEM DISCONNECT SESSION ClauseSession
- alter session force parallel query與執行計劃變化SessionParallel
- alter system kill session 不成功Session
- alter system set events 相關知識
- alter system set events 知識 [final]
- alter system set events相關知識:
- alter system set events相關知識
- Session store not set on request.Session
- Laravel - Session store not set on requestLaravelSession
- Alter system kill session and ORA-00031: session marked for killSession
- 【Oracle】alter system set events 相關知識Oracle
- ALTER SYSTEM KILL SESSION這麼沒力?(轉)Session
- alter system set events相關知識(轉帖2)