为什么Oracle odbc驱动程序不为整数和数字类型提供TYPE_NAME?

时间:2012-07-24 16:18:23

标签: oracle odbc oracle11g unixodbc

我正在尝试使用odbc动态创建表,我需要获取要在create table语句中使用的正确类型字符串。但是,似乎无法从Oracle驱动程序获取任何TYPE_NAME字符串(oracle-instantclient11.2-odbc-11.2.0.1.0-1.x86_64)。 使用以下类型调用SQLGetTypeInfo(hStmt,sqlType)始终返回空记录:

SQL_NUMERIC,SQL_INTEGER,SQL_BIGINT

我分别期待NUMERIC,NUMERIC(10,0)和NUMERIC(19,0)。或NUMBER替换http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#i16209中列出的数字:NUMBER(p,s)

相反,SQL_ALL_TYPES列表显示NUMBER没有任何支持,而是有一个未记录的(如前面提到的链接)DECIMAL类型。

知道这种行为的原因以及如何在不必检查驱动程序连接DBMS名称的情况下获取正确的字符串?

PS:     SQL_ALL_TYPES返回:     BLOB,LONG RAW,BFILE,RAW,CLOB,LONG,CHAR,DECIMAL,BINARY_FLOAT,     BINARY_DOUBLE,DOUBLE PRECISION,DATE,VARCHAR2,NCHAR,NVARCHAR2,NCLOB

1 个答案:

答案 0 :(得分:0)

Oracle存储数值数据类型如下

NUMERIC:SQL_DECIMAL = 3 size 38,0
NUMERIC(10,0):SQL_DECIMAL = 3大小10,0 NUMERIC(19,0):SQL_DECIMAL = 3大小19,0

最后一位数字是比例,例如: -

NUMERIC(12,3):SQL_DECIMAL = 3 size 12,3

Easysoft等商业驱动程序支持ODBC中的require数据类型: -

Full Connect(Default)

Env. Attr. SQL_ATTR_ODBC_VERSION set to SQL_OV_ODBC3

Successfully connected to DSN 'ESOracle32'.
SQLGetTypeInfo:
                In:             StatementHandle = 0x00DD7C58, DataType = SQL_INTEGER=4
                Return: SQL_SUCCESS=0

Get Data All:
"TYPE_NAME", "DATA_TYPE", "COLUMN_SIZE", "LITERAL_PREFIX", "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE", "SEARCHABLE", "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE", "AUTO_UNIQUE_VALUE", "LOCAL_TYPE_NAME", "MINIMUM_SCALE", "MAXIMUM_SCALE", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "NUM_PREC_RADIX", "INTERVAL_PRECISION"
"INTEGER", 4, 9, <Null>, <Null>, <Null>, 1, 0, 3, 0, 0, 0, "NUMBER(9)", <Null>, <Null>, 6, <Null>, 10, <Null>
1 row fetched from 19 columns.

SQLGetTypeInfo:
                In:             StatementHandle = 0x00DD7C58, DataType = SQL_NUMERIC=2
                Return: SQL_SUCCESS=0

Get Data All:
"TYPE_NAME", "DATA_TYPE", "COLUMN_SIZE", "LITERAL_PREFIX", "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE", "SEARCHABLE", "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE", "AUTO_UNIQUE_VALUE", "LOCAL_TYPE_NAME", "MINIMUM_SCALE", "MAXIMUM_SCALE", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "NUM_PREC_RADIX", "INTERVAL_PRECISION"
"NUMBER", 2, 38, <Null>, <Null>, "precision,scale", 1, 0, 3, 0, 0, 0, "NUMBER", <Null>, <Null>, 2, <Null>, 10, <Null>
1 row fetched from 19 columns.