查詢Oracle使用者資訊的方法!!!

2022-09-10 06:12:12 字數 3887 閱讀 8568

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';

9、oracle刪除指定使用者所有表的方法

select 'drop table '||table_name||';' from all_tables where owner='要刪除的使用者名稱(注意要大寫)';

10、刪除使用者

drop user user_name cascade; 如:drop user smchannel cascade

11、獲取當前使用者下所有的表:

select table_name from user_tables;

12、刪除某使用者下所有的表資料:

select 'truncate table ' || table_name from user_tables;

13、禁止外來鍵 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'

14、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;

連帶表間的外來鍵關係一起刪除所有某個使用者下的所有表:

select

'drop table

'||tname||

'cascade constraint ;

'from dba_objects from dba_objects where owner=

'your_user

'and object_type=

'table

'

**:

oracle 查詢使用者相關資訊

表 select from all tables where owner upper system 索引 select from all indexes where owner upper system 檢視 select from all views where owner upper syste...

Oracle 使用者資訊查詢,操作語句

dba 需要有許可權才能檢視,否則會報表和檢視不存在的錯誤 1.查詢所有使用者 username,tablespace 資訊 select from dba users select from all users 當前使用者 select from user users 2.檢視使用者或角色的系統許...

Oracle 使用者資訊查詢,操作語句

dba 需要有許可權才能檢視,否則會報表和檢視不存在的錯誤 1.查詢所有使用者 username,tablespace 資訊 select from dba users select from all users 當前使用者 select from user users 2.檢視使用者或角色的系統許...