Oracle获取列数据大小
我是 Oracle 数据库的新手,我想知道是否可以找到数据类型和数据大小...... 我的意思是:假设我在表“products”中有 varchar2(20) 类型的列“location”。 我可以编写一个查询来返回结果“varchar2”和“20”吗?
谢谢你!
I'm new to Oracle db, and i wonder if i can find out the datatype and datasize...
I mean : let's say i have the column "location" of type varchar2(20) in table "products".
Could i write a query that would return me in the result "varchar2" and "20" ?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看user_tab_columns。
Check out user_tab_columns.
您是否需要找出列的类型和大小以了解数据,或者您是否正在编写需要在运行时了解它的程序?
如果您只需要了解一下,在 SQLPlus 中输入
desc tablename
将告诉您表中的列。如果您需要以编程方式找出类型和大小,您使用什么语言... PL/SQL?爪哇?
请注意,从 USER_TAB_COLUMNS 中进行选择将仅列出您自己的架构中的表中的列。对于其他表,您需要查看 ALL_TAB_COLUMNS(或 DBA_TAB_COLUMNS,如果 DBA 允许您访问它)。请注意,您的雇主或客户可能不允许针对其中任何一个进行编译存储过程或包。
Do you need to find out the type and size of a column for the purpose of understanding the data, or are you writing a program that needs to know it at runtime?
If you only need to know it for your knowledge, typing
desc tablename
in SQLPlus will tell you about the columns in the table.If you need to find out the type and size programmatically, what language are you using ... PL/SQL? Java?
Note that selecting from USER_TAB_COLUMNS will only list the columns in tables in your own schema. For other tables you'll need to look at ALL_TAB_COLUMNS (or DBA_TAB_COLUMNS, if the DBA has allowed you to access it). Note that your employer or client may disallow stored procedures or packages from being compiled against either.
我从 sqlplus for oracle 执行以下操作:
希望它也适合您!
I do the following from sqlplus for oracle:
Hope it works for you too!
这个问题的答案对我很有用。但是,当列类型为
NVARCAHR2
时,在获取 data_length 时需要考虑一个重要的差异。为NVARCHA2
列返回的 data_length 加倍。这是由于使用的字符编码造成的。
Oracle 文档 说:
因此,理想的查询如下:
The answer to this question was useful to me. But, there is one important difference needs to be considered while taking data_length when the column type is
NVARCAHR2
. The data_length returned forNVARCHA2
column is doubled.This is due to the character encoding being used.
Oracle documentation says:
So, ideal query would be the following: