如何查询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;
oracle 新建用户
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 c 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;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。