Question

I am trying to create a table dynamically with odbc and I need to get the correct type string to use in the create table statement. However it seems there is no way to get any TYPE_NAME string from the Oracle driver (oracle-instantclient11.2-odbc-11.2.0.1.0-1.x86_64). Calling SQLGetTypeInfo(hStmt, sqlType) with the following types always returns an empty recordest:

SQL_NUMERIC, SQL_INTEGER, SQL_BIGINT

I was expecting respectively NUMERIC, NUMERIC(10,0) and NUMERIC(19,0). Or NUMBER replacing numeric as listed in http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#i16209 : NUMBER(p,s)

Instead, a list of SQL_ALL_TYPES reveals no support at all for NUMBER but instead there is an undocumented (as for the aforementioned link) DECIMAL type.

Any idea of why this behaviour and how to get the correct string without having to examine the driver connection DBMS name?

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

Was it helpful?

Solution

Oracle stores the numeric data types as follows

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

The last digit is the scale so for exmaple :-

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

Commercial drivers such as Easysoft do support the require data types in ODBC :-

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top