1,對其它用戶下的表執行trundate table操作
開發說在用dwetl下執行調用shop用戶下的表的時候提示沒有權限操作,google了查了下,發現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
----------
1
SQL>
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
begin
execute 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 selected
SQL>
以上所述是小編給大家介紹的Oracle給用戶授權truncatetable的實現方案,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
您可能感興趣的文章:- delete from 表名與truncate table 表名區別
- SQL中Truncate的用法
- golang實戰之truncate日志文件詳解
- tf.truncated_normal與tf.random_normal的詳細用法
- smarty中改進truncate使其支持中文的方法
- SQL Server中TRUNCATE事務回滾操作方法
- 實例理解SQL中truncate和delete的區別
- 詳解SQL中drop、delete和truncate的異同
- Mysql開啟慢SQL并分析原因
- Truncate Table的用法講解