如何在不使用 DESCRIBE 命令的情况下描述 Oracle 中的表?

2023-09-18数据库问题
1

本文介绍了如何在不使用 DESCRIBE 命令的情况下描述 Oracle 中的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在上课时遇到了困难.我们需要编写一个与 DESCRIBE 命令类似的 Oracle 脚本.我们正在使用的这本书描述了如何非常糟糕地使用数据字典.不是在寻找答案,而是在正确的方向上找到一个点.

I'm having a hard time with a class I am taking. We need to write an Oracle script that will act just like the DESCRIBE command. The book we are using describes how to work with the Data Dictionary very poorly. Not looking for answers, but a point in the correct direction.

推荐答案

您正在寻找 USER_TAB_COLUMNS - 所有列及其在执行查询的架构中的描述 - 或 ALL_TAB_COLUMNS - 除了用户有权查看的所有表外都相同.

You're looking for USER_TAB_COLUMNS - all the columns, and their descriptions in the schema the query is executed in - or ALL_TAB_COLUMNS - the same except for all tables that user has permission to view.

一个典型的查询可能是:

A typical query might be:

select *
  from user_tab_columns
 where table_name = 'MY_TABLE'
 order by column_id

column_id 是表中列的顺序".

你应该确保'MY_TABLE'是大写的,除非你一直在添加带有大小写的表格(一个坏主意),在这种情况下你需要使用类似="MyTable"的东西.

You should ensure that 'MY_TABLE' is capitalised unless you've been adding tables with casing ( a bad idea ) in which case you need to use something like = "MyTable".

特别是 desc 等价于我从 ss64 中窃取的以下内容,一个优秀的 Oracle资源:

Specifically desc is equivalent to the following which I stole from ss64, a good Oracle resource:

select column_name as "Name"
     , nullable as "Null?"
     , concat(concat(concat(data_type,'('),data_length),')') as "Type"
  from user_tab_columns
 where table_name = 'MY_TABLE';

您可以通过select * from dictionary找到所有此类视图,这是数据字典 或查看文档.

You can find all of this sort of view by select * from dictionary, which is the top level of the data dictionary or by looking at the documentation.

还有 DBA_TAB_COLUMNS,它与 ALL_TAB_COLUMNS 相同,但适用于数据库中的每个表.这假设您具有查看它和表的权限.如果您无权访问此表,则需要让您的 DBA 授予您 SELECT ANY DICTIONARY 权限.

There is also the DBA_TAB_COLUMNS, which is the same as ALL_TAB_COLUMNS, but for every table in the database. This assumes that you have the privileges to view both it and the tables. If you do not have access to this table you need to get your DBA to grant you the SELECT ANY DICTIONARY privilege.

这篇关于如何在不使用 DESCRIBE 命令的情况下描述 Oracle 中的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13