Oracle資料庫預存程序與許可權

來源:互聯網
上載者:User

在執行預存程序時,我們可能會遇到許可權問題

● 定義者許可權預存程序
● 調用者許可權預存程序

在資料庫中建立預存程序時,定義者許可權是預設模式
當指定AUTHID CURRENT_USER關鍵字後,便是調用者許可權預存程序
他倆之間最根本的差異在於role能否在預存程序中生效

㈠ 定義者許可權預存程序問題
定義者許可權預存程序role無效,必須要有顯式授權
即便是擁有dba role,還是不能訪問不同使用者的表

sys@EMREP> grant connect,resource to u1 identified by u1;Grant succeeded.sys@EMREP> grant dba to u2 identified by u2;Grant succeeded.sys@EMREP> conn u1/u1Connected.u1@EMREP> create table t as select * from user_objects;Table created.sys@EMREP> conn u2/u2Connected.u2@EMREP> create or replace procedure p_test  2  as  3  begin  4    delete from u1.t;  5    commit;  6  end;  7  /Warning: Procedure created with compilation errors.u2@EMREP> show error;Errors for PROCEDURE P_TEST:LINE/COL ERROR-------- -----------------------------------------------------------------4/3      PL/SQL: SQL Statement ignored4/18     PL/SQL: ORA-00942: table or view does not existu2@EMREP> conn u1/u1Connected.u1@EMREP> grant all on t to u2;Grant succeeded.u1@EMREP> conn u2/u2Connected.u2@EMREP> create or replace procedure p_test  2  as  3  begin  4    delete from u1.t;  5    commit;  6  end;  7  /Procedure created.

㈡ 調用者許可權預存程序問題
調用者許可權預存程序role編譯不可見,但運行時可見
用動態SQL避免直接授權,而將許可權的檢查延後至運行時

u2@EMREP> conn u1/u1           Connected.u1@EMREP> revoke all on t from u2;Revoke succeeded.u1@EMREP> conn u2/u2Connected.u2@EMREP> create or replace procedure p_test  2  authid current_user  3  as  4  begin  5    delete from u1.t;  6    commit;  7  end;  8  /Warning: Procedure created with compilation errors.u2@EMREP> show error;Errors for PROCEDURE P_TEST:LINE/COL ERROR-------- -----------------------------------------------------------------5/3      PL/SQL: SQL Statement ignored5/18     PL/SQL: ORA-00942: table or view does not existu2@EMREP> create or replace procedure p_test  2  authid current_user  3  as  4  begin  5    execute immediate  6   'delete from u1.t';  7    commit;  8  end;  9  /Procedure created.u2@EMREP> exec p_test;PL/SQL procedure successfully completed.u2@EMREP> select count(*) from u1.t;  COUNT(*)----------         0
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.