查詢Oracle中全部用戶信息,刪除用戶、表,禁止外鍵等。 1.查看全部用戶: select * from dba_users; select * from all_users; select * from user_users; 2.查看用戶或角色系統權限(直接賦值給用戶或角色的系統權限): select * from dba_sys_privs; select * from user_sys_privs; (查看當前用戶所擁有的權限) 3.查看角色(只能查看登錄用戶擁有的角色)所包含的權限 sql>select * from role_sys_privs; 4.查看用戶對象權限: select * from dba_tab_privs; select * from all_tab_privs; select * from user_tab_privs; 5.查看全部角色: select * from dba_roles; 6.查看用戶或角色所擁有的角色: select * from dba_role_privs; select * from user_role_privs; 7.查看哪些用戶有sysdba或sysoper系統權限(查詢時須要相應權限) select * from V$PWFILE_USERS 8.SqlPlus中查看一個用戶所擁有權限 SQL>select * from dba_sys_privs where grantee='username'; 其中的username即用戶名要大寫才行。 好比: SQL>select * from dba_sys_privs where grantee='TOM'; 九、Oracle刪除指定用戶全部表的方法 select 'Drop table '||table_name||';' from all_tables where owner='要刪除的用戶名(注意要大寫)'; 十、刪除用戶 drop user user_name cascade; 如:drop user SMCHANNEL CASCADE 十一、獲取當前用戶下全部的表: select table_name from user_tables; 十二、刪除某用戶下全部的表數據: select 'truncate table ' || table_name from user_tables; 1三、禁止外鍵 ORACLE數據庫中的外鍵約束名都在表user_constraints中能夠查到。 其中constraint_type='R'表示是外鍵約束。 啓用外鍵約束的命令爲:alter table table_name enable constraint constraint_name 禁用外鍵約束的命令爲:alter table table_name disable constraint constraint_name 而後再用SQL查出數據庫中因此外鍵的約束名: select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R' select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R' 1四、ORACLE禁用/啓用外鍵和觸發器 --啓用腳本 SET SERVEROUTPUT ON SIZE 1000000 BEGIN for c in (select 'ALTER TABLE '||TABLE_NAME||' ENABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop DBMS_OUTPUT.PUT_LINE(C.V_SQL); begin EXECUTE IMMEDIATE c.v_sql; exception when others then dbms_output.put_line(sqlerrm); end; end loop; for c in (select 'ALTER TABLE '||TNAME||' ENABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop dbms_output.put_line(c.v_sql); begin execute immediate c.v_sql; exception when others then dbms_output.put_line(sqlerrm); end; end loop; end; / commit; --禁用腳本 SET SERVEROUTPUT ON SIZE 1000000 BEGIN for c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop DBMS_OUTPUT.PUT_LINE(C.V_SQL); begin EXECUTE IMMEDIATE c.v_sql; exception when others then dbms_output.put_line(sqlerrm); end; end loop; for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop dbms_output.put_line(c.v_sql); begin execute immediate c.v_sql; exception when others then dbms_output.put_line(sqlerrm); end; end loop; end; / commit;