Oracle获取列数据大小

发布于 2024-10-17 06:31:45 字数 147 浏览 1 评论 0原文

我是 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 技术交流群。

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

发布评论

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

评论(5

鹿港巷口少年归 2024-10-24 06:31:45

查看user_tab_columns

select data_type, data_length 
  from user_tab_columns
 where table_name = 'PRODUCTS'
   and column_name = 'LOCATION';

Check out user_tab_columns.

select data_type, data_length 
  from user_tab_columns
 where table_name = 'PRODUCTS'
   and column_name = 'LOCATION';
梦在深巷 2024-10-24 06:31:45

您是否需要找出列的类型和大小以了解数据,或者您是否正在编写需要在运行时了解它的程序?

如果您只需要了解一下,在 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.

花海 2024-10-24 06:31:45

我从 sqlplus for oracle 执行以下操作:

SELECT COLUMN_NAME,DATA_TYPE,DATA_LENGTH 
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME = 'YOUR_TABLE_NAME'
AND COLUMN_NAME = 'YOUR';`

希望它也适合您!

I do the following from sqlplus for oracle:

SELECT COLUMN_NAME,DATA_TYPE,DATA_LENGTH 
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME = 'YOUR_TABLE_NAME'
AND COLUMN_NAME = 'YOUR';`

Hope it works for you too!

爱你不解释 2024-10-24 06:31:45
SELECT CHAR_LENGTH FROM USER_TAB_COLUMNS WHERE TABLE_NAME = <TABLENAME> AND COLUMN_NAME = <COLUMNNAME>;     
SELECT CHAR_LENGTH FROM USER_TAB_COLUMNS WHERE TABLE_NAME = <TABLENAME> AND COLUMN_NAME = <COLUMNNAME>;     
凉城 2024-10-24 06:31:45

这个问题的答案对我很有用。但是,当列类型为 NVARCAHR2 时,在获取 data_length 时需要考虑一个重要的差异。为 NVARCHA2 列返回的 data_length 加倍。

这是由于使用的字符编码造成的。
Oracle 文档 说:

字节数最多可以是 AL16UTF16 大小的两倍
编码和 UTF8 编码的三倍大小。

因此,理想的查询如下:

select table_name, column_name, 
data_type, NVL(char_col_decl_length, data_length) 
from user_tab_columns where table_name='T51_NOCOMP';

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 for NVARCHA2 column is doubled.

This is due to the character encoding being used.
Oracle documentation says:

The number of bytes can be up to two times size for AL16UTF16
encoding and three times size for UTF8 encoding.

So, ideal query would be the following:

select table_name, column_name, 
data_type, NVL(char_col_decl_length, data_length) 
from user_tab_columns where table_name='T51_NOCOMP';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文