Increase VARCHAR2, NVARCHAR2, And RAW Data Types Size
Starting with 12c we can extend the size for VARCHAR2, NVARCHAR2 and RAW data types. The modification is done by setting MAX_STRING_SIZE init parameter. Possible values are { STANDARD | EXTENDED } where:
STANDARD = same as pre-12c configuration. Maximum size is 4000 bytes for VARHCAR2, NVARCHAR2 and 2000 bytes for RAW.
EXTENDED = maximum size is 32767 bytes.
In order to be able to set MAX_STRING_SIZE = EXTENDED the database must be 12c with init parameter COMPATIBLE set to 12.0.0.0 or higher. The trick when performing the change is that the database/container must be opened in UPGRADE mode. If you are using multitenant architecture remember that this is container based change (in other words, if you want to make the change in all containers than you’ll have to make the change in each of the containers separately).
When column data type size is declared with up to 4000 bytes for VARCHAR2, NVARCHAR2) and up to 2000 bytes for RAW, the column is known to be stored as inline. If the column data type is declared with size higher than 4000 up to 32767 the column is known to be stored as out-of-line. When the column is stored out-of-line internally LOB segment is created for column storage.
Important note: You can’t go back from EXTENDED to STANDARD mode.
In this post I’ll cover how to change MAX_STRING_SIZE for specific PDB. If you’re interested on how can you perform this change for non-CDB, RAC or Logical DG take a look at Oracle Reference Guide MAX_STRING_SIZE.
With default setting MAX_STRING_SIZE = STANDARD, if we try to specify higher size e.g. for VARCHAR2 we would get ORA-00910 error.
How to change MAX_STRING_SIZE in a PDB?
From ROOT container close the PDB (if it’s already opened) and startup in UPGRADE mode.
From PDB container set MAX_STRING_SIZE to ‘EXTENDED’.
Confirm that you’ve set the MAX_STRING_SIZE correctly. If you are not familiar with init parameters for PDBs read this post for more details.
Run $ORACLE_HOME/rdbms/admin/utl32k.sql from PDB container logged as SYSDBA.
After you’ve run the script open the PDB in normal mode.
Because utl32k.sql invalidates some system views and synonyms we need to run @?/rdbms/admin/utlrp.sql to re-validate invalid objects.
At the end if you like you can perform small test to confirm that the change is successful.
As previously specified when the column is stored out-of-place LOB segment is internally created for column storage.
Restrictions
There are several restrictions with extended character data types.
– If we have already existing indexed columns in order to be able to increase the size we have to drop the indexes, increase the columns size and as last step re-create the indexes on those columns.
It’s not supported for index-organized tables and clustered tables
However, we can still specify size up to 4000 bytes (column is stored inline) without any problems.
There is also restriction on intrapartition parallel operations on DDL, DML, DELETE DML and direct-path inserts for tables in ASSM managed tablespace.