用于列出数据库中所有模式的 Oracle SQL 查询

发布于 2024-10-15 05:42:10 字数 52 浏览 2 评论 0原文

我想删除 Oracle DB 上一些未使用的模式。

如何查询所有架构名称?

I wanted to delete some unused schemas on our oracle DB.

How can I query for all schema names ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

心的位置 2024-10-22 05:42:10

使用 sqlplus

sqlplus / as sysdba

运行:

SELECT * 
FROM dba_users

如果您只想要用户名,请执行以下操作:

SELECT username 
FROM dba_users

Using sqlplus

sqlplus / as sysdba

run:

SELECT * 
FROM dba_users

Should you only want the usernames do the following:

SELECT username 
FROM dba_users
凉城凉梦凉人心 2024-10-22 05:42:10

最有可能的是,您希望

SELECT username
  FROM dba_users

这将向您显示系统中的所有用户(以及所有潜在的模式)。如果您对“模式”的定义允许模式为空,那么这就是您想要的。但是,可能存在语义区别,即人们只想将某事物称为模式(如果它实际上拥有至少一个对象),以便排除数百个永远不会拥有任何对象的用户帐户。在这种情况下,

SELECT username
  FROM dba_users u
 WHERE EXISTS (
    SELECT 1
      FROM dba_objects o
     WHERE o.owner = u.username )

假设创建模式的人对于分配默认表空间是明智的,并且假设您对 Oracle 提供的模式不感兴趣,则可以通过在 default_tablespace 上添加谓词来过滤掉这些模式,即

SELECT username
  FROM dba_users
 WHERE default_tablespace not in ('SYSTEM','SYSAUX')

或者,

SELECT username
  FROM dba_users u
 WHERE EXISTS (
    SELECT 1
      FROM dba_objects o
     WHERE o.owner = u.username )
   AND default_tablespace not in ('SYSTEM','SYSAUX')

遇到系统中有人错误地为非系统用户提供 default_tablespaceSYSTEM 的情况并不少见,因此请确保之前的假设成立尝试以这种方式过滤掉 Oracle 提供的模式。

Most likely, you want

SELECT username
  FROM dba_users

That will show you all the users in the system (and thus all the potential schemas). If your definition of "schema" allows for a schema to be empty, that's what you want. However, there can be a semantic distinction where people only want to call something a schema if it actually owns at least one object so that the hundreds of user accounts that will never own any objects are excluded. In that case

SELECT username
  FROM dba_users u
 WHERE EXISTS (
    SELECT 1
      FROM dba_objects o
     WHERE o.owner = u.username )

Assuming that whoever created the schemas was sensible about assigning default tablespaces and assuming that you are not interested in schemas that Oracle has delivered, you can filter out those schemas by adding predicates on the default_tablespace, i.e.

SELECT username
  FROM dba_users
 WHERE default_tablespace not in ('SYSTEM','SYSAUX')

or

SELECT username
  FROM dba_users u
 WHERE EXISTS (
    SELECT 1
      FROM dba_objects o
     WHERE o.owner = u.username )
   AND default_tablespace not in ('SYSTEM','SYSAUX')

It is not terribly uncommon to come across a system where someone has incorrectly given a non-system user a default_tablespace of SYSTEM, though, so be certain that the assumptions hold before trying to filter out the Oracle-delivered schemas this way.

转身泪倾城 2024-10-22 05:42:10
SELECT username FROM all_users ORDER BY username;
SELECT username FROM all_users ORDER BY username;
傾旎 2024-10-22 05:42:10
select distinct owner 
from dba_segments
where owner in (select username from dba_users where default_tablespace not in ('SYSTEM','SYSAUX'));
select distinct owner 
from dba_segments
where owner in (select username from dba_users where default_tablespace not in ('SYSTEM','SYSAUX'));
剑心龙吟 2024-10-22 05:42:10

下面的sql列出了oracle中安装后创建的所有schema
ORACLE_MAINTAINED='N' 是过滤器。此列是 12c 中的新增内容。

select distinct username,ORACLE_MAINTAINED from dba_users where ORACLE_MAINTAINED='N';

Below sql lists all the schema in oracle that are created after installation
ORACLE_MAINTAINED='N' is the filter. This column is new in 12c.

select distinct username,ORACLE_MAINTAINED from dba_users where ORACLE_MAINTAINED='N';
☆獨立☆ 2024-10-22 05:42:10

怎么样:

SQL> select * from all_users;

它将返回所有用户/模式的列表、他们的 ID 和在数据库中创建的日期:

USERNAME                          USER_ID CREATED
------------------------------ ---------- ---------
SCHEMA1                         120 09-SEP-15
SCHEMA2                         119 09-SEP-15
SCHEMA3                         118 09-SEP-15

How about :

SQL> select * from all_users;

it will return list of all users/schemas, their ID's and date created in DB :

USERNAME                          USER_ID CREATED
------------------------------ ---------- ---------
SCHEMA1                         120 09-SEP-15
SCHEMA2                         119 09-SEP-15
SCHEMA3                         118 09-SEP-15
伴梦长久 2024-10-22 05:42:10

以下任一 SQL 将返回 Oracle DB 中的所有模式。

  1. 从 all_tables 中按所有者分组选择所有者;
  2. 从 all_tables 中选择不同的所有者;

Either of the following SQL will return all schema in Oracle DB.

  1. select owner FROM all_tables group by owner;
  2. select distinct owner FROM all_tables;
嘿哥们儿 2024-10-22 05:42:10

如果您想搜索架构名称,那么

SELECT * FROM all_tables WHERE OWNER  LIKE '%SCHEMA_NAME%'

如果您想搜索特定表,那么 -

SELECT * FROM all_tables WHERE TABLE_NAME  LIKE '%TABLE_NAME%'

IF YOU WANT TO SEARCH FOR THE SCHEMA NAME THEN

SELECT * FROM all_tables WHERE OWNER  LIKE '%SCHEMA_NAME%'

iF YOU WANT TO SEARCH FOR PERTICULAR TABLE THEN -

SELECT * FROM all_tables WHERE TABLE_NAME  LIKE '%TABLE_NAME%'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文