附註:
- 此教學課程需要存取 Oracle Cloud。若要註冊免費帳戶,請參閱開始使用 Oracle Cloud Infrastructure Free Tier 。
- 它會使用 Oracle Cloud Infrastructure 證明資料、租用戶及區間的範例值。完成實驗室時,請將這些值替代為您雲端環境特定的值。
啟用 Oracle 資料庫的擴充資料類型功能
簡介
Oracle Database 12c 導入了 MAX_STRING_SIZE 參數,可控制 VARCHAR2、NVARCHAR2 及 RAW 資料類型的大小上限。將 MAX_STRING_SIZE 參數設為 EXTENDED 可將資料類型大小設為 32767 位元組限制。將 MAX_STRING_SIZE 設定為 EXTENDED 值時,資料庫 COMPATIBLE 初始化參數應為 12.0.0.0 或更新的版本。
本教學課程詳細說明啟用 Oracle Database 的作業,以充分運用需要特定升級動作的新擴充資料類型。
目標
- 運用支援的 VARCHAR2、NVARCHAR2 及 RAW 資料類型上限為 32767 個位元組。
必要條件
- 資料庫版本應為 Oracle 12.2 或更新版本。
作業 1:在非容器資料庫上設定擴充資料類型
-
執行下列命令。
SQL> SHOW PARAMETER MAX_STRING_ | NAME | TYPE | VALUE | | --------------- | ------ | -------- | | max_string_size | string | STANDARD |
-
以升級模式啟動資料庫。
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.
-
將
MAX_STRING_SIZE
值變更為 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 |
-
執行
utl32k.sql
程序檔:@?/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.
-
重新啟動資料庫。
shutdown immediate; startup SQL> show parameter max_string | NAME | TYPE | VALUE | | --------------- | ------ | -------- | | max_string_size | string | EXTENDED |
作業 2:設定容器資料庫上的擴充資料類型 (CDB$ROOT)
-
執行下列命令。
[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.
-
將
MAX_STRING_SIZE
值變更為 EXTENDED。SQL> ALTER SYSTEM SET MAX_STRING_SIZE=extended SCOPE=SPFILE; System altered.
-
以升級模式啟動資料庫。
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
-
執行
catcon.pl
程序檔。注意:使用
catcon.pl
程序檔在 root 與 CDB 中的所有 PDB 中執行rdbms/admin/utl32k.sql
命令檔,以增加 VARCHAR2、NVARCHAR2 和 RAW 資料欄的大小上限。-force_pdb_mode 'UPGRADE' 選項可用來確保所有 PDB (包括應用程式根複製) 皆以移轉模式開啟。提示時輸入 SYS 密碼。[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 |
作業 3:在 PDB 上設定擴充的資料類型
-
執行下列命令以更改資料庫。
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 |
-
以升級模式開啟 PDB RATPRD_PDB1,需要修改 max_string_size 參數。
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 |
-
執行 utl32k.sql 以修改 PDB RATPRD_PDB1 上 VARCHAR2、NVARCHAR2 以及 RAW 資料欄的大小上限。
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.
-
驗證 max_string_size 參數值已變更為 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 |
相關連結
確認書
- 作者 - Hakim Ahamad (主要雲端架構師)
其他學習資源
探索 docs.oracle.com/learn 的其他實驗室,或者存取更多 Oracle Learning YouTube 頻道上的免費學習內容。此外,請瀏覽 education.oracle.com/learning-explorer 以成為 Oracle Learning 檔案總管。
如需產品文件,請造訪 Oracle Help Center 。
Enable the Extended Data Type Capability for Oracle databases
F87592-01
October 2023
Copyright © 2023, Oracle and/or its affiliates.