在12C中,varchar2,nvarchar2和raw類型從之前的4K擴展到32K
升級到12C后,參數max_string_size默認值是standard,即不改變varchar2、nvarchar2、和raw數據類型的大小限制,和11g保持一致。
SQL> show parameter max_string_size NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ max_string_size string STANDARD SQL>
開啟"擴展數據類型"功能:
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 SQL> --設置該參數需要將數據以upgrade模式啟動 SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup upgrade; ORACLE instance started. Total System Global Area 2483027968 bytes Fixed Size 3713864 bytes Variable Size 721421496 bytes Database Buffers 1744830464 bytes Redo Buffers 13062144 bytes Database mounted. Database opened. SQL> alter system set max_string_size=extended scope=both; System altered. SQL> @$ORACLE_HOME/rdbms/admin/utl32k.sql
修改以后要執行以下腳本,升級后可能會有部分對象變得無效,需要重新編譯下一無效對象
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
升級以后,如果varchar2,nvarchar2和raw的大小超過4k,oracle內部會以LOBs的方式存儲(oracle內部自己維護,不建議用戶直接操作)。
然后再重啟數據庫!
可以做個測試:
SQL> create table v32k_t (id int,name varchar2(32000)); SQL> insert into v32k_t values(1,rpad(1,31999,'x')); SQL> select * from v32k_t;
該新特性會產生以下一些影響:
(1)The creation and use of indexes is impacted (as covered in the next section in more detail).
用戶可能會無法正確的創建、使用索引,或者無法插入和更新操作。
這主要受oracle的B樹索引的長度限制,而B樹索引的長度又受數據庫塊大小限制。8k大小的塊所支持的索引的最大長度是6400字節。
建議可以使用substr創建函數索引,或創建hash索引;使用substr創建虛擬列,然后在虛擬列上創建索引。
(2)The limit of the combined length of concatenated character strings is increased.
(3)The length of the collation key returned by the NLSSORT function is increased.
(4)The size of some of the attributes of the XMLFormat objects is increased.
(5)The size of some expressions in some XML functions is adjusted.
