如何使用 OracleTypeCHAR 元数据获取 Oracle 对象类型中声明的 VARCHAR2 属性的长度,而不考虑数据库字符集

发布于 2024-10-18 00:21:16 字数 371 浏览 3 评论 0原文

我的 Java 应用程序依赖于 Oracle 对象类型元数据。我使用 oracle.jdbc.oracore.OracleTypeCHAR 类通过 JDBC 访问这些元数据。 结果相比乘以 4 - 例如:

some_attribute varchar2(10)

将数据库转换为字符集 AL32UTF8 后,OracleTypeCHAR#getLength() 方法返回的结果与 Oracle 对象类型中声明的 当使用前一个字符集返回长度 10 时,结果为长度 40。有没有办法在不解析OOT源代码的情况下从PL/SQL获取原始值?

My Java application depends on Oracle Object Types metadata. I use oracle.jdbc.oracore.OracleTypeCHAR class to access these metadata with JDBC. After converting the database to charset AL32UTF8, the OracleTypeCHAR#getLength() method returns results multiplied by factor of 4 comparing to what is declared in Oracle Object Type - for example:

some_attribute varchar2(10)

Would result in lenght 40, when lenght 10 was returned with the previous charset. Is there a way to obtain the raw value from PL/SQL without parsing OOT source code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

神仙妹妹 2024-10-25 00:21:16

字符列的字符长度可以在user_tab_columns.CHAR_LENGTH中找到,

select column_name, comments from all_col_comments where table_name = 'USER_TAB_COLUMNS';

COLUMN_NAME          COMMENTS

TABLE_NAME           Table, view or cluster name
COLUMN_NAME          Column name
DATA_TYPE            Datatype of the column
DATA_TYPE_MOD        Datatype modifier of the column
DATA_TYPE_OWNER      Owner of the datatype of the column
DATA_LENGTH          Length of the column in bytes
DATA_PRECISION       Length: decimal digits (NUMBER) or binary digits (FLOAT)
DATA_SCALE           Digits to right of decimal point in a number
NULLABLE             Does column allow NULL values?
COLUMN_ID            Sequence number of the column as created
DEFAULT_LENGTH       Length of default value for the column
DATA_DEFAULT         Default value for the column
NUM_DISTINCT         The number of distinct values in the column
LOW_VALUE            The low value in the column
HIGH_VALUE           The high value in the column
DENSITY              The density of the column
NUM_NULLS            The number of nulls in the column
NUM_BUCKETS          The number of buckets in histogram for the column
LAST_ANALYZED        The date of the most recent time this column was analyzed
SAMPLE_SIZE          The sample size used in analyzing this column
CHARACTER_SET_NAME   Character set name
CHAR_COL_DECL_LENGTH Declaration length of character type column
GLOBAL_STATS         Are the statistics calculated without merging underlying partitions?
USER_STATS           Were the statistics entered directly by the user?
AVG_COL_LEN          The average length of the column in bytes
CHAR_LENGTH          The maximum length of the column in characters
CHAR_USED            C is maximum length given in characters, B if in bytes
V80_FMT_IMAGE        Is column data in 8.0 image format?
DATA_UPGRADED        Has column data been upgraded to the latest type version format?
HISTOGRAM

使用此查询可以查找该列的字符长度,

select
  char_length
from
  user_tab_columns
where
  table_name = 'T' and column_name = 'SOME_ATTRIBUTE';

The character length for a character column can be found in user_tab_columns.CHAR_LENGTH,

select column_name, comments from all_col_comments where table_name = 'USER_TAB_COLUMNS';

COLUMN_NAME          COMMENTS

TABLE_NAME           Table, view or cluster name
COLUMN_NAME          Column name
DATA_TYPE            Datatype of the column
DATA_TYPE_MOD        Datatype modifier of the column
DATA_TYPE_OWNER      Owner of the datatype of the column
DATA_LENGTH          Length of the column in bytes
DATA_PRECISION       Length: decimal digits (NUMBER) or binary digits (FLOAT)
DATA_SCALE           Digits to right of decimal point in a number
NULLABLE             Does column allow NULL values?
COLUMN_ID            Sequence number of the column as created
DEFAULT_LENGTH       Length of default value for the column
DATA_DEFAULT         Default value for the column
NUM_DISTINCT         The number of distinct values in the column
LOW_VALUE            The low value in the column
HIGH_VALUE           The high value in the column
DENSITY              The density of the column
NUM_NULLS            The number of nulls in the column
NUM_BUCKETS          The number of buckets in histogram for the column
LAST_ANALYZED        The date of the most recent time this column was analyzed
SAMPLE_SIZE          The sample size used in analyzing this column
CHARACTER_SET_NAME   Character set name
CHAR_COL_DECL_LENGTH Declaration length of character type column
GLOBAL_STATS         Are the statistics calculated without merging underlying partitions?
USER_STATS           Were the statistics entered directly by the user?
AVG_COL_LEN          The average length of the column in bytes
CHAR_LENGTH          The maximum length of the column in characters
CHAR_USED            C is maximum length given in characters, B if in bytes
V80_FMT_IMAGE        Is column data in 8.0 image format?
DATA_UPGRADED        Has column data been upgraded to the latest type version format?
HISTOGRAM

Use this query to find the character length of the column,

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