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.
相关问题
- Can I skip certificate verification oracle utl_htt
- how to calculate sum time with data type char in o
- keeping one connection to DB or opening closing pe
- System.Data.OracleClient not working with 64 bit O
- How can I get rid of dynamic SQL
相关文章
- node连接远程oracle报错
- oracle 11g expdp导出作业调用失败,提示丢包。
- 执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- Difference between FOR UPDATE OF and FOR UPDATE
- Oracle USING clause best practice
- Is there a method in PL/SQL to convert/encode text
- PHP PDO installation on windows (xampp)
Oracle has a set tables containing meta data about the database structure. There is a table of tables. A table of views. A table of columns. You can query these tables by using views such as USER_TABLES (tables in your schema), ALL_TABLES (tables you have permission to view), DBA_TABLES (all tables, if you have the privileges). More generically, many database vendors support the "information schema" which provides a consistent view of the meta data across vendors. Search for "ALL_TABLES" here and look at all the other information available http://docs.oracle.com/cd/B28359_01/server.111/b28320/toc.htm
Newly introduced in Oracle SQLcl is the
information
command or simplyINFO table_name
. It has a simple syntax likeDESC[RIBE]
:Its output is far superior and descriptive compared to
DESCRIBE
. It Lists more detailed information about the column definitions for a table, view or synonym, or the specifications for a function or procedure.For eg: This is the output I get in SQLcl: Release 18.1.1 when I run
info employees
Here is a screen shot with
info+
:You can also retrieve the entire command that can be used to recreate the table:
You're looking for
USER_TAB_COLUMNS
- all the columns, and their descriptions in the schema the query is executed in - orALL_TAB_COLUMNS
- the same except for all tables that user has permission to view.A typical query might be:
column_id
is the "order" of the column in the table.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"
.Specifically
desc
is equivalent to the following which I stole from ss64, a good Oracle resource: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.There is also the
DBA_TAB_COLUMNS
, which is the same asALL_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 theSELECT ANY DICTIONARY
privilege.