[20130915]12c新特性 varchar2支援32K長度.txt

lfree發表於2013-09-17
[20130915]12c新特性 varchar2支援32K長度.txt

oracle 12c以前如果字串長度超過4000,必須使用blob或者clob型別。12c開始支援超過4000的字串長度,提高一些應用的靈活性,
達到32K,避免一些欄位定義為clob,blob型別,提高處理能力。

但是12c預設的方式不支援大於4000的字串長度,必須經過一些步驟升級完成,自己測試如下:

SYS@test> @ver

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

SYS@test> show parameter max_string_size
NAME             TYPE    VALUE
---------------- ------- -----------
max_string_size  string  STANDARD

SYS@test> alter system set max_string_size='EXTENDED' ;
alter system set max_string_size='EXTENDED'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-02095: specified initialization parameter cannot be modified
--不能線上修改這個引數。

SYS@test> alter system set max_string_size='EXTENDED'  scope=spfile ;
System altered.

--修改spfile的引數檔案。shutdown immediate,進入升級模式startup upgrade;,呼叫@?/rdbms/admin/utl32k.sql。

SYS@test> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@test> startup upgrade;
ORACLE instance started.
Total System Global Area 1670221824 bytes
Fixed Size                  2403352 bytes
Variable Size            1006633960 bytes
Database Buffers          654311424 bytes
Redo Buffers                6873088 bytes
Database mounted.
Database opened.
SYS@test> @?/rdbms/admin/utl32k.sql
...

--如果存在pdb庫,還必須升級PDB$SEED,以及PDB資料庫,不然會出現如下提示,在啟動時。
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-14696: MAX_STRING_SIZE migration is incomplete for pluggable database PDB$SEED
Process ID: 1192
Session ID: 355 Serial number: 5

SYS@test> startup upgrade
ORACLE instance started.

Total System Global Area 1670221824 bytes
Fixed Size                  2403352 bytes
Variable Size            1006633960 bytes
Database Buffers          654311424 bytes
Redo Buffers                6873088 bytes
Database mounted.
Database opened.

SYS@test> ALTER SESSION SET CONTAINER = PDB$SEED;
Session altered.
SYS@test> @?/rdbms/admin/utl32k.sql
...

SYS@test> ALTER SESSION SET CONTAINER = TEST01p;
Session altered.

SYS@test> alter pluggable database test01p open upgrade;
Pluggable database altered.

SYS@test> @?/rdbms/admin/utl32k.sql
...

--再重新啟動資料庫,OK。

SYS@test> startup
ORACLE instance started.

Total System Global Area 1670221824 bytes
Fixed Size                  2403352 bytes
Variable Size            1023411176 bytes
Database Buffers          637534208 bytes
Redo Buffers                6873088 bytes
Database mounted.
Database opened.
SYS@test> alter pluggable database test01p open ;
Pluggable database altered.

==以scott使用者test01p服務:
SCOTT@test01p> create table t1 (id number,text varchar2(32767));
Table created.

SCOTT@test01p> insert into t1 values (1,lpad('a',32767,'b'));
1 row created.

--OK,現在可以使用32K的字串,實際上是32767的長度。

SCOTT@test01p> create table t2 (id number,text varchar2(32768));
create table t1 (id number,text varchar2(32768))
                                         *
ERROR at line 1:
ORA-00910: specified length too long for its datatype

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-772855/,如需轉載,請註明出處,否則將追究法律責任。

相關文章