Database 12c: Extended Datatypes


Starting with 12c Extended Datatypes has been introduced. I’m going to show how to use the new feature. If you have installed default 12.1.0.1 database you will get the following error when trying to create a table with varchar2 greater 4000 bytes:

SQL> create table tab1 (id number,text varchar2(32767 byte));
create table tab1 (id number,text varchar2(32767 byte))
                                           *
ERROR at line 1:
ORA-00910: specified length too long for its datatype

There is a new parameter called “MAX_STRING_SIZE”. Here the parameter and values:

  • 32767 bytes or characters if MAX_STRING_SIZE = EXTENDED
  • 4000 bytes or characters if MAX_STRING_SIZE = STANDARD

The parameter cannot be changed at session level…

SQL> alter session set max_string_size=EXTENDED;
alter session set max_string_size=EXTENDED
*
ERROR at line 1:
ORA-02096: specified initialization parameter is not modifiable with this option

If you try to change a system level:

SQL> alter system set max_string_size=EXTENDED scope=both;
alter system set max_string_size=EXTENDED scope=both
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-14694: database must in UPGRADE mode to begin MAX_STRING_SIZE migration

OK enough for testing. Here the steps to change this parameter:

0. Requirements

To activate the feature the parameter COMPATIBLE must at least 12.0.0.0.

1. change parameter

SQL>  alter system set max_string_size=EXTENDED scope=spfile;

System altered.

SQL>

2. shutdown immediate

[bash]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Mon Jul 22 21:53:59 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

3. startup upgrade

SQL> startup upgrade
ORACLE instance started.

Total System Global Area 2488635392 bytes
Fixed Size                  2291424 bytes
Variable Size             671090976 bytes
Database Buffers         1795162112 bytes
Redo Buffers               20090880 bytes
Database mounted.
Database opened.

5. run script 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.

0 rows updated.

Commit complete.

System altered.

PL/SQL procedure successfully completed.

Commit complete.

System altered.

Session altered.

PL/SQL procedure successfully completed.

No errors.

Session altered.

PL/SQL procedure successfully completed.

Commit complete.

Package altered.

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN  2013-07-22 21:43:09

DOC>   The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC>   objects in the database. Recompilation time is proportional to the
DOC>   number of invalid objects in the database, so this command may take
DOC>   a long time to execute on a database with a large number of invalid
DOC>   objects.
DOC>
DOC>   Use the following queries to track recompilation progress:
DOC>
DOC>   1. Query returning the number of invalid objects remaining. This
DOC>      number should decrease with time.
DOC>         SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC>   2. Query returning the number of objects compiled so far. This number
DOC>      should increase with time.
DOC>         SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC>   This script automatically chooses serial or parallel recompilation
DOC>   based on the number of CPUs available (parameter cpu_count) multiplied
DOC>   by the number of threads per CPU (parameter parallel_threads_per_cpu).
DOC>   On RAC, this number is added across all RAC nodes.
DOC>
DOC>   UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC>   recompilation. Jobs are created without instance affinity so that they
DOC>   can migrate across RAC nodes. Use the following queries to verify
DOC>   whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC>   1. Query showing jobs created by UTL_RECOMP
DOC>         SELECT job_name FROM dba_scheduler_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC>   2. Query showing UTL_RECOMP jobs that are running
DOC>         SELECT job_name FROM dba_scheduler_running_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#

PL/SQL procedure successfully completed.

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_END  2013-07-22 21:43:11

DOC> The following query reports the number of objects that have compiled
DOC> with errors.
DOC>
DOC> If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#

OBJECTS WITH ERRORS
-------------------
                  0

DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#

ERRORS DURING RECOMPILATION
---------------------------
                          0

Function created.

PL/SQL procedure successfully completed.

Function dropped.

...Database user "SYS", database schema "APEX_040200", user# "98" 21:43:19
...Compiled 0 out of 2998 objects considered, 0 failed compilation 21:43:20
...263 packages
...255 package bodies
...453 tables
...11 functions
...16 procedures
...3 sequences
...458 triggers
...1322 indexes
...207 views
...0 libraries
...6 types
...0 type bodies
...0 operators
...0 index types
...Begin key object existence check 21:43:20
...Completed key object existence check 21:43:20
...Setting DBMS Registry 21:43:20
...Setting DBMS Registry Complete 21:43:20
...Exiting validate 21:43:20

PL/SQL procedure successfully completed.

SQL>

This script is mandatory, else you will get the following error:

SQL> startup
ORACLE instance started.

Total System Global Area 2488635392 bytes
Fixed Size                  2291424 bytes
Variable Size             671090976 bytes
Database Buffers         1795162112 bytes
Redo Buffers               20090880 bytes
Database mounted.
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-14695: MAX_STRING_SIZE migration is incomplete
Process ID: 6324
Session ID: 355 Serial number: 5

NOTE:
The utl32k.sql script increases the maximum size of the VARCHAR2, NVARCHAR2, and RAW columns
for the views where this is required. The script does not increase the maximum size of the
VARCHAR2, NVARCHAR2, and RAW columns in some views because of the way the SQL for those views is written.

5. startup normal

SQL> startup
ORACLE instance started.

Total System Global Area 2488635392 bytes
Fixed Size                  2291424 bytes
Variable Size             671090976 bytes
Database Buffers         1795162112 bytes
Redo Buffers               20090880 bytes
Database mounted.
Database opened.
SQL> show parameter max_string_size

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
max_string_size                      string      EXTENDED
SQL>

NOW: test it

SQL> conn hr/hr
Connected.
SQL> create table tab1 (id number,text varchar2(32767));

Table created.

SQL> desc tab1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER
 TEXT                                               VARCHAR2(32767)

SQL>

Changing MAX_STRING_SIZE in PDBs

  1. Shut down the PDB.
  2. Restart the PDB in UPGRADE mode.
  3. Change the setting of MAX_STRING_SIZE in the PDB to EXTENDED.
  4. Run the @?/rdbms/admin/utl32k.sql script in the PDB. You must be connected AS SYSDBA to run the utl32k.sql script.
  5. Restart the PDB in NORMAL mode.

Changing MAX_STRING_SIZE in RAC

  1. Shut down all of the Oracle RAC database instances, except one.
  2. Restart the Oracle RAC database instance in UPGRADE mode.
  3. Change the setting of MAX_STRING_SIZE to EXTENDED.
  4. Run the @?/rdbms/admin/utl32k.sql script in the Oracle RAC database instance. You must be connected AS SYSDBA to run the script.
  5. Restart the Oracle RAC database instance in NORMAL mode.
  6. Restart the other Oracle RAC database instances in NORMAL mode.

Changing MAX_STRING_SIZE in DG Environment

  1. Shut down the Oracle Data Guard primary database and logical standby database.
  2. Restart the primary database and logical standby database in UPGRADE mode.
  3. Change the setting of MAX_STRING_SIZE to EXTENDED on the primary database and logical standby database.
  4. Run the @?rdbms/admin/utl32k.sql script on both the primary database and the logical standby database. You must be connected AS SYSDBA to run the script.
  5. Restart the primary database and logical standby database in NORMAL mode and start SQL Apply.

Bug 15845247

If you change the MAX_STRING_SIZE initialization parameter while creating a database using DBCA with a template that includes data files, the database creation fails with the following error:
ORA-14694: database must in UPGRADE mode to begin MAX_STRING_SIZE migration

Workaround: Leave the MAX_STRING_SIZE initialization parameter set to the default (STANDARD) or whatever it was set to in the template during DBCA. If you need to create a database with MAX_STRING_SIZE=EXTENDED, use the custom database template in DBCA.In a multitenant container database (CDB), the MAX_STRING_SIZE initialization parameter is a per-PDB parameter. The root CDB always uses STANDARD semantics, regardless of the parameter. You can change the MAX_STRING_SIZE initialization parameter for PDBs as needed after the CDB is created.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s