Note:

Enable the Extended Data Type Capability for Oracle databases

Introduction

Oracle Database 12c introduced MAX_STRING_SIZE parameter which control the maximum size of VARCHAR2, NVARCHAR2 and RAW data types. Setting MAX_STRING_SIZE parameter to EXTENDED enables the data type size to 32767 byte limit. While setting MAX_STRING_SIZE to EXTENDED value, database COMPATIBLE initialization parameter should be 12.0.0.0 or higher version.

This tutorial details the tasks for Enabling Oracle Database to take advantage of the new extended data types which requires specific upgrade actions.

Objectives

Prerequisites

Task 1: Set the Extended Data Type on a Non-Container Database

  1. Run the following command.

    SQL> SHOW PARAMETER MAX_STRING_
    
    | NAME            | TYPE   | VALUE    |
    | --------------- | ------ | -------- |
    | max_string_size | string | STANDARD |
    
  2. Start the database in upgrade mode.

    SQL> SHUTDOWN IMMEDIATE;
    
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    
    SQL>STARTUP UPGRADE
    
    ORACLE instance started.
    
    Total System Global Area   1.4663E+10 bytes
    Fixed Size                 15697000 bytes
    Variable Size              1.1878E+10 bytes
    Database Buffers           2717908992 bytes
    Redo Buffers               51404800 bytes
    
    Database mounted.
    Database opened.
    
  3. Change the MAX_STRING_SIZE value to EXTENDED.

    SQL>  alter system set MAX_STRING_SIZE='EXTENDED' SCOPE=BOTH;
    
    System altered.
    
    SQL> show parameter MAX_STRING_SIZE
    
    | NAME            | TYPE   | VALUE    |
    | --------------- | ------ | -------- |
    | max_string_size | string | EXTENDED |
    
  4. Run the utl32k.sql script: @?/rdbms/admin/utl32k.sql.

    SQL> @?/rdbms/admin/utl32k.sql
    
    Session altered.
    
    DOC>#######################################################################
    DOC>#######################################################################
    DOC> The following statement will cause an "ORA-01722: invalid number"
    DOC> error if the database has not been opened for UPGRADE.
    DOC>
    DOC> Perform a "SHUTDOWN ABORT" and
    DOC> restart using UPGRADE.
    DOC>#######################################################################
    DOC>#######################################################################
    DOC>#
    
    no rows selected
    
    DOC>#######################################################################
    DOC>#######################################################################
    DOC> The following statement will cause an "ORA-01722: invalid number"
    DOC> error if the database does not have compatible >= 12.0.0
    DOC>
    DOC> Set compatible >= 12.0.0 and retry.
    DOC>#######################################################################
    DOC>#######################################################################
    DOC>#
    
    PL/SQL procedure successfully completed.
    
    Session altered.
    
    1524 rows updated.
    
    Commit complete.
    
    System altered.
    
    PL/SQL procedure successfully completed.
    
    Commit complete.
    
    System altered.
    
    Session altered.
    
    Session altered.
    
    Table created.
    
    Table created.
    
    Table created.
    
    Table truncated.
    
    0 rows created.
    
    PL/SQL procedure successfully completed.
    
    no rows selected
    
    DOC>#######################################################################
    DOC>#######################################################################
    DOC> The following statement will cause an "ORA-01722: invalid number"
    DOC> error if we encountered an error while modifying a column to
    DOC> account for data type length change as a result of enabling or
    DOC> disabling 32k types.
    DOC>
    DOC> Contact Oracle support for assistance.
    DOC>#######################################################################
    DOC>#######################################################################
    DOC>#
    
    PL/SQL procedure successfully completed.
    
    PL/SQL procedure successfully completed.
    
    Commit complete.
    
  5. Restart the database.

    shutdown immediate;
    startup
    
    SQL> show parameter max_string
    
    | NAME            | TYPE   | VALUE    |
    | --------------- | ------ | -------- |
    | max_string_size | string | EXTENDED |
    

Task 2: Set the Extended Data Type on a Container Database (CDB$ROOT)

  1. Run the following commands.

    [oracle@vm4 ~]$ sqlplus "/ as sysdba"
    
    SQL*Plus: Release 12.2.0.1.0 Production on Thu Sep 7 13:26:41 2023
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 12c EE Extreme Perf Release 12.2.0.1.0 - 64bit Production
    
    SQL> SHOW PARAMETER MAX_STRING_
    
    | NAME            | TYPE   | VALUE    |
    | --------------- | ------ | -------- |
    | max_string_size | string | STANDARD |
    
    SQL> show pdbs;
    
    | CON_ID | CON_NAME    | OPEN MODE  | RESTRICTED |
    | ------ | ----------- | ---------- | ---------- |
    | 2      | PDB$SEED    | READ ONLY  | NO         |
    | 3      | RATPRD_PDB1 | READ WRITE | NO         |
    
    [oracle@vm4 ~]$ cd $ORACLE_HOME/rdbms/admin
    [oracle@vm4 admin]$ pwd
    /u01/app/oracle/product/12.2.0.1/dbhome_1/rdbms/admin
    [oracle@vm4 ~]$  mkdir -p /home/oracle/mydir/utl32k_cdb_pdbs_output
    [oracle@vm4 ~]$ sqlplus "/ as sysdba"
    
    SQL*Plus: Release 12.2.0.1.0 Production on Thu Sep 7 13:30:18 2023
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 12c EE Extreme Perf Release 12.2.0.1.0 - 64bit Production
    
    SQL> ALTER SESSION SET CONTAINER=CDB$ROOT;
    
    Session altered.
    
  2. Change the MAX_STRING_SIZE value to EXTENDED.

    SQL> ALTER SYSTEM SET MAX_STRING_SIZE=extended SCOPE=SPFILE;
    
    System altered.
    
  3. Start database in upgrade mode.

    SQL> shutdown;
    
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    
    SQL> startup upgrade;
    
    ORACLE instance started.
    
    Total System Global Area 3.2749E+10 bytes
    Fixed Size                 12351112 bytes
    Variable Size            4160751992 bytes
    Database Buffers         2.8387E+10 bytes
    Redo Buffers              188973056 bytes
    
    Database mounted.
    Database opened.
    
    SQL> exit
    
  4. Run the catcon.pl script.

    Note: Use the catcon.pl script to run the rdbms/admin/utl32k.sql script in the root and in all the PDBs in the CDB to increase the maximum size of the VARCHAR2, NVARCHAR2, and RAW columns. The –force_pdb_mode ‘UPGRADE’ option is used to ensure that all PDBs, including application root clones, are opened in migrate mode. Enter the SYS password when prompted.

    [oracle@vm4 ~]$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u SYS --force_pdb_mode 'UPGRADE' -d $ORACLE_HOME/rdbms/admin -l '/home/oracle/mydir/utl32k_cdb_pdbs_output' -b utl32k_cdb_pdbs_output utl32k.sql
    catcon: ALL catcon-related output will be written to [/home/oracle/mydir/utl32k_cdb_pdbs_output/utl32k_cdb_pdbs_output_catcon_88242.lst]
    catcon: See [/home/oracle/mydir/utl32k_cdb_pdbs_output/utl32k_cdb_pdbs_output*.log] files for output generated by scripts
    catcon: See [/home/oracle/mydir/utl32k_cdb_pdbs_output/utl32k_cdb_pdbs_output_*.lst] files for spool files, if any
    Enter Password:    -> enter sys password
    catcon.pl: completed successfully
    [oracle@vm4 ~]$ sqlplus "/ as sysdba"
    
    SQL*Plus: Release 12.2.0.1.0 Production on Thu Sep 7 13:48:56 2023
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 12c EE Extreme Perf Release 12.2.0.1.0 - 64bit Production
    
    SQL> startup;
    
    ORA-01081: cannot start already-running ORACLE - shut it down first
    
    SQL> shut immediate;
    
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    
    SQL> startup;
    
    ORACLE instance started.
    
    Total System Global Area 3.2749E+10 bytes
    Fixed Size                 12351112 bytes
    Variable Size            4160751992 bytes
    Database Buffers         2.8387E+10 bytes
    Redo Buffers              188973056 bytes
    
    Database mounted.
    Database opened.
    
    SQL> show parameter max_string_size;
    
    | NAME            | TYPE   | VALUE    |
    | --------------- | ------ | -------- |
    | max_string_size | string | EXTENDED |
    

Task 3: Set the extended Data Type on PDB

  1. Run the following commands to alter the database.

    SQL> alter session set container = RATPRD_PDB1;
    
    Session altered.
    
    SQL> show pdbs
    
    | CON_ID | CON_NAME    | OPEN MODE  | RESTRICTED |
    | ------ | ----------- | ---------- | ---------- |
    | 3      | RATPRD_PDB1 | READ WRITE | NO         |
    
    SQL> ALTER PLUGGABLE DATABASE RATPRD_PDB1 CLOSE IMMEDIATE;
    
    Pluggable database altered.
    
    SQL>  show pdbs
    
    | CON_ID | CON_NAME    | OPEN MODE | RESTRICTED |
    | ------ | ----------- | --------- | ---------- |
    | 3      | RATPRD_PDB1 | MOUNTED   |
    
  2. Open PDB RATPRD_PDB1 in upgrade mode, required to modify max_string_size parameter.

    SQL> ALTER PLUGGABLE DATABASE RATPRD_PDB1 OPEN UPGRADE;
    
    $
    Pluggable database altered.
    
    SQL>  show pdbs;
    
    | CON_ID | CON_NAME    | OPEN MODE | RESTRICTED |
    | ------ | ----------- | --------- | ---------- |
    | 3      | RATPRD_PDB1 | MIGRATE   | YES        |
    
  3. Run utl32k.sql to modify the maximum size of the VARCHAR2,NVARCHAR2, and RAW columns On PDB RATPRD_PDB1.

    SQL> @$ORACLE_HOME/rdbms/admin/utl32k.sql;
    
    Session altered.
    
    DOC>#######################################################################
    DOC>#######################################################################
    DOC> The following statement will cause an "ORA-01722: invalid number"
    DOC> error if the database has not been opened for UPGRADE.
    DOC>
    DOC> Perform a "SHUTDOWN ABORT" and
    DOC> restart using UPGRADE.
    DOC>#######################################################################
    DOC>#######################################################################
    DOC>#
    
    no rows selected
    
    DOC>#######################################################################
    DOC>#######################################################################
    DOC> The following statement will cause an "ORA-01722: invalid number"
    DOC> error if the database does not have compatible >= 12.0.0
    DOC>
    DOC> Set compatible >= 12.0.0 and retry.
    DOC>#######################################################################
    DOC>#######################################################################
    DOC>#
    
    PL/SQL procedure successfully completed.
    
    Session altered.
    
    0 rows updated.
    
    Commit complete.
    
    System altered.
    
    PL/SQL procedure successfully completed.
    
    Commit complete.
    
    System altered.
    
    Session altered.
    
    Session altered.
    
    Table created.
    
    Table created.
    
    Table created.
    
    Table truncated.
    
    0 rows created.
    
    PL/SQL procedure successfully completed.
    
    STARTTIME :
    
    09/07/2023 14:32:06.790646000
    
    PL/SQL procedure successfully completed.
    
    No errors.
    
    PL/SQL procedure successfully completed.
    
    Session altered.
    
    Session altered.
    
    0 rows created.
    
    no rows selected
    
    no rows selected
    
    DOC>#######################################################################
    DOC>#######################################################################
    DOC> The following statement will cause an "ORA-01722: invalid number"
    DOC> error if we encountered an error while modifying a column to
    DOC> account for data type length change as a result of enabling or
    DOC> disabling 32k types.
    DOC>
    DOC> Contact Oracle support for assistance.
    DOC>#######################################################################
    DOC>#######################################################################
    DOC>#
    
    PL/SQL procedure successfully completed.
    
    PL/SQL procedure successfully completed.
    
    Commit complete.
    
    Package altered.
    
    Package altered.
    
    SQL> show pdbs;
    
    | CON_ID | CON_NAME    | OPEN MODE | RESTRICTED |
    | ------ | ----------- | --------- | ---------- |
    | 3      | RATPRD_PDB1 | MIGRATE   | YES        |
    
    SQL> ALTER PLUGGABLE DATABASE RATPRD_PDB1 CLOSE IMMEDIATE;
    
    Pluggable database altered.
    
  4. Validate the max_string_size parameter value is changed to EXTENDED.

    SQL> ALTER PLUGGABLE DATABASE RATPRD_PDB1 open ;
    
    Pluggable database altered.
    
    SQL>  show pdbs;
    
    | CON_ID | CON_NAME    | OPEN MODE  | RESTRICTED |
    | ------ | ----------- | ---------- | ---------- |
    | 3      | RATPRD_PDB1 | READ WRITE | NO         |
    
    SQL> show parameter max_string_size;
    
    | NAME            | TYPE   | VALUE    |
    | --------------- | ------ | -------- |
    | max_string_size | string | EXTENDED |
    

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.