When you change the data type of a column in the Oracle mode of OceanBase Database, you must first follow the table-level column type change rules, especially in scenarios where some data types are forbidden, and then follow the change rules of the source data type and target data type.
Table-level column type change rules
Prohibitory rules
FOREIGN KEY constraints
For both online and offline DDL operations: You can only increase or decrease the precision of data types
VARCHAR,VARCHAR2, andNVARCHAR2.Trigger constraints
For only offline DDL operations: You cannot change the data type of a column with any triggers not in the
DISABLEstate. If all triggers are in theDISABLEstate, DDL operations are not affected and the new table must contain the triggers in theDISABLEstate.Partitioning keys
For both online and offline DDL operations: If a column is a part of the partitioning key, you cannot change the data type or length of this column.
For both online and offline DDL operations: If a column is referenced by a generated column, you cannot change the data type of this column.
Change rules
You can change the length of a column without changing its data type. For example, you can change a
CHARcolumn to aCHAR(11)column. Since OceanBase Database allows you to perform online DDL operations to storeCHARdata without rewriting data, if the column is referenced by an index table, you can change the length of this column by performing an online DDL operation. If the column is used as a primary key or partitioning key, you need to perform offline DDL operations to change its length. If the column has aCHECKconstraint, the column may violate theCHECKconstraint after its length is changed and therefore you also need to perform offline DDL operations to change its length. In other words, perform offline DDL operations to change the length of a column without changing its data type when the column has a CHECK constraint, or when it is used as a primary key or partitioning key.You can perform online DDL operations to change the length of a
VARCHARcolumn. Because when you perform operations such as specifyingLENGTH(c1), the column length remains unchanged. However, you must also change the schema of objects, such as index tables, that depend on this column. In this case, even if the column is used as a primary key or partitioning key, you can still perform online DDL operations to change the column length. In other words, the schemas of objects that depend on this column need to be changed even though the expected data does not change.In OceanBase Database, the type change of a column may occur within a category of data types (such as numeric, character, datetime and interval, and rowid data types). If this column is not referenced by an index table, foreign key,
CHECKconstraint, or primary key, you can perform online DDL operations to change the column type. Otherwise, you need to perform offline DDL operations to change the column type. In other words, offline DDL operations are required for column type change if any objects depend on the column.To convert a
SIGNEDnumeric column to anUNSIGNEDnumeric column (or vice versa), you need to perform offline DDL operations if the change is allowed.
Column-level change rules
In OceanBase Database, all column data types are classified into the following categories: numeric, character, datetime, interval, and rowid data types.
In the current version of OceanBase Database, both the ROWID and UROWID types are implemented as the UROWID type inside the database. Therefore, the conversion rules between UROWID and UROWID also apply between ROWID and UROWID.
In the Oracle mode of OceanBase Database, conversions among data types of different categories are not allowed. The following sections describe the conversion between data types of the same category.
Conversion between numeric data types
Numeric data types include the following ones:
NUMBERFLOATNotice
FLOAT(p)is not a floating-point data type. It is a subtype of theNUMBERdata type. Its binary precision range is [1, 126].BINARY_FLOATBINARY_DOUBLE
The following table describes the conversion between numeric data types.
| Data type | NUMBER | FLOAT | BINARY_FLOAT | BINARY_DOUBLE |
|---|---|---|---|---|
NUMBER |
Supported | Supported | Unsupported | Unsupported |
FLOAT |
Supported | Supported | Unsupported | Unsupported |
BINARY_FLOAT |
Unsupported | Unsupported | Supported | Unsupported |
BINARY_DOUBLE |
Unsupported | Unsupported | Unsupported | Supported |
Conversion between character data types
Character data types include the following ones:
CHARVARCHARandVARCHAR2:VARCHARandVARCHAR2are the same data type.NCHARandNVARCHAR2: All characters are represented in two bytes.BLOB: The character set isBINARY.CLOB: The character set isUTF8MB4.RAW: RAW data is stored in binary format regardless of the character set.
The following table describes the conversion between character data types.
| Data type | To CHAR | To VARCHAR and VARCHAR2 | To NCHAR | To NVARCHAR2 | To BLOB | To CLOB | To RAW |
|---|---|---|---|---|---|---|---|
CHAR |
Supported | Supported | Supported | Unsupported | Unsupported | Unsupported | Unsupported |
VARCHAR and VARCHAR2 |
Supported | Supported | Supported | Unsupported | Unsupported | Unsupported | Unsupported |
NCHAR |
Unsupported | Unsupported | Supported | Supported | Unsupported | Unsupported | Unsupported |
NVARCHAR2 |
Unsupported | Unsupported | Supported | Supported | Unsupported | Unsupported | Unsupported |
BLOB |
Unsupported | Unsupported | Unsupported | Unsupported | Supported | Unsupported | Unsupported |
CLOB |
Unsupported | Unsupported | Unsupported | Unsupported | Unsupported | Supported | Unsupported |
RAW |
Unsupported | Unsupported | Unsupported | Unsupported | Unsupported | Unsupported | Supported |
Conversion between datetime data types
Datetime data types include the following ones:
DATETIMESTAMPTIMESTAMP WITH TIME ZONETIMESTAMP WITH LOCAL TIME ZONE
The following table describes the conversion between datetime data types.
| Data type | To DATE | To TIMESTAMP | To TIMESTAMP WITH TIME ZONE | To TIMESTAMP WITH LOCAL TIME ZONE |
|---|---|---|---|---|
DATE |
Supported | Supported | Supported | Supported |
TIMESTAMP |
Supported | Supported | Unsupported | Unsupported |
TIMESTAMP WITH TIME ZONE |
Unsupported | Unsupported | Supported | Unsupported |
TIMESTAMP WITH LOCAL TIME ZONE |
Supported | Unsupported | Unsupported | Supported |
Conversion between interval data types
Interval data types include the following ones:
INTERVAL YEAR TO MONTHINTERVAL DAY TO SECOND
The following table describes the conversion between interval data types.
| Data type | To INTERVAL YEAR TO MONTH | To INTERVAL DAY TO SECOND |
|---|---|---|
| INTERVAL YEAR TO MONTH | Supported | Unsupported |
| INTERVAL DAY TO SECOND | Unsupported | Supported |
Conversion between rowid data types
Rowid data types include the following ones:
ROWIDUROWID
The following table describes the conversion between rowid data types.
| Data type | To ROWID | To UROWID |
|---|---|---|
| ROWID | Supported | Supported |
| UROWID | Supported | Supported |