oracle包的使用(二)

Nalternative發表於2011-02-19

set termout off

結果不輸出到螢幕上,只在指令碼中有效。@D:\demo01.sql


一、--檢視當前會話

1SQL>  select sid from v$mystat where rownum=1;

 

       SID

----------

       134

2SQL> SELECT SYS_CONTEXT( 'USERENV', 'SID' ) FROM DUAL;

 

SYS_CONTEXT('USERENV','SID')

--------------------------------------------------------------------------------

134


二、設定檢視會話的client_info

SQL> SELECT sys_context('USERENV', 'CLIENT_INFO') FROM dual;

 

SYS_CONTEXT('USERENV','CLIENT_

--------------------------------------------------------------------------------

192.168.5.223

 

SQL> exec dbms_application_info.set_client_info('TEST');

 

PL/SQL procedure successfully completed

 

SQL> SELECT sys_context('USERENV', 'CLIENT_INFO') FROM dual;

 

SYS_CONTEXT('USERENV','CLIENT_

--------------------------------------------------------------------------------

TEST

DBMS_APPLICATION_INFO 可以設定SESSIONMODULEACTIONCLIENT INFO等狀態資訊,對應著V$SESSION表中的3個欄位


三、DBMS_ALERT包提供了註冊,傳送和接收告警的能力。

declare

    l_msg   long;

    l_status number;

begin

    dbms_alert.register( 'WAITING' );

    for i in 1 .. 999999 loop

        dbms_application_info.set_client_info( i );

        dbms_alert.waitone( 'WAITING', l_msg, l_status, 0 );

        exit when l_status = 0;

        for x in ( select * from big_table order by 1, 2, 3, 4 )

        loop

            null;

        end loop;

    end loop;

end;

/

當執行下邊的語句時,上邊的會話停止

begin

  dbms_alert.signal('WAITING','');

  COMMIT;

END;


四、dbms_aw.eval_number
select dbms_aw.eval_number('1*2*3*4') from dual
24

 
五、檢視物件的許可權
select DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','EDUCATE') from dual

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25323853/viewspace-687557/,如需轉載,請註明出處,否則將追究法律責任。

相關文章