广告
返回顶部
首页 > 资讯 > 数据库 > 查询oracle中所有用户信息(转)
  • 295
分享到

查询oracle中所有用户信息(转)

摘要

----查询oracle中所有用户信息 ----1、查询数据库中的表空间名称 ----1)查询所有表空间 select tablespace_name from dba_tablespaces; select tab


	查询oracle中所有用户信息(转)
[数据库教程]

----查询oracle中所有用户信息
----1、查询数据库中的表空间名称

----1)查询所有表空间

select tablespace_name from dba_tablespaces;
select tablespace_name from user_tablespaces;

----2)查询使用过的表空间  

select distinct tablespace_name from dba_all_tables;

select distinct tablespace_name from user_all_tables;

----2、查询表空间中所有表的名称

select *  from dba_all_tables where tablespace_name = ‘SYNC_PLUS_1‘ and owner=‘GDSDCZJ‘

----3、查询系统用户

select * from all_users
select * from dba_users

----4、查看当前连接用户

select * from v$session

----5、查看当前用户权限

select * from session_privs

----6、查看所有的函数和存储过程

select * from user_source

----其中TYPE包括:PROCEDURE、FUNCTION

----7、查看表空间使用情况
select  sum(Bytes_size) from (
select a.file_id "FileNo",
       a.tablespace_name "表空间",
       a.bytes/1024/1021/1024 Bytes_size,
       a.bytes - sum(nvl(b.bytes, 0)) "已用",
       sum(nvl(b.bytes, 0)) "空闲",
       sum(nvl(b.bytes, 0)) / a.bytes * 100 "空闲百分率"
  from dba_data_files a, dba_free_space b
 where a.file_id = b.file_id(+)
 group by a.tablespace_name, a.file_id, a.bytes
 order by a.tablespace_name
 );




-----------------------------------------------------

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

转自 https://www.cnblogs.com/iOS9/p/9100185.html

查询oracle中所有用户信息(转)

原文地址:Https://www.cnblogs.com/Heoric/p/13926468.html

您可能感兴趣的文档:

--结束END--

本文标题: 查询oracle中所有用户信息(转)

本文链接: https://www.lsjlt.com/news/7925.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作