Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change size of varchar2 column of an Oracle database in liquibase

Tags:

liquibase

I have a simple need to increase the size of a VARCHAR2 column in an Oracle DB from VARCHAR2(20 CHAR) to VARCHAR2(35 CHAR).

The database is used by an existing application with production data though I will start with DEV first (of course).

like image 597
Robert R Avatar asked Nov 15 '15 22:11

Robert R


People also ask

Can we increase column size in Oracle?

Oracle allows you to perform many actions but the following are the main ones: Modify the column's visibility. Allow or not allow null values. Shorten or widen the size of the column.

What is VARCHAR2 max size?

The maximum length for VARCHAR2 is 32672 BYTE or 8168 CHAR which is the same as the maximum length for VARCHAR of 32672 OCTETS or 8168 CODEUNITS32. Similarly, when the NVARCHAR2 data type is explicitly encountered in SQL statements, it is implicitly mapped following the same rules as the NVARCHAR data type.

Can we change number to VARCHAR2 in Oracle?

TO_CHAR (number) converts n to a value of VARCHAR2 datatype, using the optional number format fmt . The value n can be of type NUMBER , BINARY_FLOAT , or BINARY_DOUBLE . If you omit fmt , then n is converted to a VARCHAR2 value exactly long enough to hold its significant digits.

What VARCHAR2 32767?

Oracle VARCHAR2 max length Since Oracle Database 12c, you can specify the maximum size of 32767 for the VARCHAR2 data type. Oracle uses the MAX_STRING_SIZE parameter for controlling the maximum size. If the MAX_STRING_SIZE is STANDARD , then the maximum size for VARCHAR2 is 4000 bytes.


1 Answers

You want to use the Liquibase refactoring "modifyDataType", which is documented here: http://www.liquibase.org/documentation/changes/modify_data_type.html

Here is an example:

<changeSet author="liquibase-docs" id="modifyDataType-example">
    <modifyDataType 
            columnName="CODE"
            newDataType="varchar2(35 char)"
            tableName="PCF_PROGRAMME"/>
</changeSet>
like image 72
SteveDonie Avatar answered Jan 02 '23 23:01

SteveDonie