Search code examples
oracle-databaseprecisionddlcreate-tableoracle18c

Unable to set precision for INTEGER data type in SQL CREATE TABLE command


I am trying to create the following table in Oracle.

CREATE TABLE CUSTOMER(CUST_ID INT(10),
CUST_NAME   VARCHAR2(50),
CUST_SEX    CHAR(2),
CUST_STATE  VARCHAR2(50),
CUST_COUNTRY    VARCHAR2(50));

I get an error saying that the right parenthesis is missing. In reality, the issue is with the INT data type for the CUST_ID column. Once I remove the precision :(10) from the DDL query, I am able to execute it successfully.

Oracle docs don't specify anything with regarding to whether this data type can be accompanied by a precision parameter or not. However Oracle does mention that INTEGER/INT is per ANSI standards.

https://docs.oracle.com/cd/B19306_01/olap.102/b14346/dml_datatypes002.htm

Certain other non-official references describe INT/INTEGER to be a synonym for NUMBER(38).

Can someone please tell me if precision cannot indeed be specified for INT datatype?


Solution

  • The Oracle docs state that:

    SQL statements that create tables and clusters can also use ANSI data types and data types from the IBM products SQL/DS and DB2. Oracle recognizes the ANSI or IBM data type name that differs from the Oracle Database data type name. It converts the data type to the equivalent Oracle data type

    As the table below that sentence states, int, integer, and (surprisingly?) smallint are all synonyms for number(38), so you cannot specify a precision for them. For your usecase, if you want an integer number with ten digits, you should use number(10).