Oracle:有没有办法获取视图的列数据类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2766361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:33:31  来源:igfitidea点击:

Oracle: Is there a way to get the column data types for a view?

oracle

提问by CodingWithSpike

For a table in oracle, I can query "all_tab_columns" and get table column information, like the data type, precision, whether or not the column is nullable.

对于oracle中的表,我可以查询“all_tab_columns”并获取表列信息,例如数据类型、精度、该列是否可以为空。

In SQL Developer or TOAD, you can click on a view in the GUI and it will spit out a list of the columns that the view returns and the same set of data (data type, precision, nullable, etc).

在 SQL Developer 或 TOAD 中,您可以单击 GUI 中的视图,它会吐出视图返回的列列表和相同的数据集(数据类型、精度、可为空等)。

So my question is, is there a way to query this column definition for a view, the way you can for a table? How do the GUI tools do it?

所以我的问题是,有没有办法像查询表一样查询视图的列定义?GUI 工具是如何做到的?

回答by René Nyffenegger

You can use user_tab_columns(or all_tab_columnsand dba_tab_columnsrespectively) regardless if table_name refers to a view or a table.

可以使用user_tab_columns(或all_tab_columnsdba_tab_columns分别),而不管是否TABLE_NAME指视图或表。

回答by Alex Poole

View columns appear in all_tab_columns, so you can query them just as you can tables.

视图列出现在 中all_tab_columns,因此您可以像查询表一样查询它们。

回答by Joy

Just simply write this query:

只需简单地编写这个查询:

SQL> desc TABLE/VIEW NAME;

For example if the table/view name is "department" Then just write:

例如,如果表/视图名称是“部门”,那么只需写:

SQL> desc department;

This will give the list of all fields, it's type and default Null info of the table or view.

这将给出所有字段的列表,它的类型和表或视图的默认 Null 信息。

回答by SQLMenace

you can use the ANSI catalog views, should work for most RDBMs

您可以使用 ANSI 目录视图,应该适用于大多数 RDBM

select * 
from information_schema.columns c
join information_schema.tables t on c.table_name = t.table_name
where table_type = 'view'