1,對其它用戶下的表執行trundate table操作
開發說在用dwetl下執行調用shop用戶下的表的時候提示沒有權限操作,google了查了下,發現oracle/246672.html">oracle賬戶沒法直接賦予對某個表的truncate權限,那要怎么來實現呢?
在shop用戶下面,準備測試數據
SQL> create table Z_TRUNCATE_T(ID number);Table created.SQL> insert into Z_TRUNCATE_T select 1 from dual;1 row created.SQL> commit;Commit complete.SQL> select * from Z_TRUNCATE_T; ID---------- 1SQL>
2,比較粗魯不安全的做法
通常賦予truncate的常規做法,是直接賦值drop any table給一個用戶
SQL> grant drop any table to dwetl;Grant succeeded.SQL> SQL> grant select,insert,delete,update on Z_TRUNCATE_T to dwetl;Grant succeeded.SQL>
干完活,需要趕緊馬上收回權限因為drop any table權限是在太大了,一不小心就會造成誤刪除,到時候哭都來不及啊
SQL> revoke drop any table from dwetl;Revoke succeeded.SQL> revoke select,insert,delete,update on shop.PLAN6_TEMPLET_NODE_EDIT from dwetl;Revoke succeeded.SQL>
3,比較安全的做法
建立一個存儲過程p_truncate,在存儲過來里面執行truncate table Z_TRUNCATE_T;然后賦予另外一個用戶dwetl對這個存儲過程的執行權限。
存儲過程p_truncate如下:
create or replace procedure p_truncate as begin execute immediate 'truncate table Z_TRUNCATE_T'; end;
建立存儲過程:
SQL> create or replace procedure p_truncate as beginexecute immediate 'truncate table Z_TRUNCATE_T'; 4 end; 5 /Procedure created.SQL>
賦予存儲過程的執行權限給dwetl,并且賦予表的增刪改查權限,因為truncate后,緊接著的基本就是insert、update、delete了
SQL> grant execute on p_truncate to dwetl;Grant succeeded.SQL> SQL> grant select,insert,delete,update on Z_TRUNCATE_T to dwetl;Grant succeeded.SQL>
通過dwetl賬號登陸,執行存儲過程查看效果,看到shop用戶下的表Z_TRUNCATE_T已經被清空了,ok,如此也證明了通過存儲過程這種方案是可行的,可以對別的用戶下的表進行truncate table操作。
–查看
SQL> call shop.p_truncate();Call completed.SQL> select * from shop.Z_TRUNCATE_T;no rows selectedSQL>
以上所述是小編給大家介紹的Oracle給用戶授權truncatetable的實現方案,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!
新聞熱點
疑難解答