12c 扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE

0    49    1

👉 本文共约5449个字,系统预计阅读时间或需21分钟。

Database SQL Language Reference ---- 》》 Data Types

img

在Oracle Database 12c中,可以指定 VARCHAR2 、 NVARCHAR2 和 RAW 数据类型的最大大小为 32767 字节。这样,用户便可以在数据库中存储更长的字符串。在本发行版之前, VARCHAR2和 NVARCHAR2 数据类型的最大大小为 4000 字节, RAW 数据类型的最大大小为 2000 字节 。声明的VARCHAR2、 NVARCHAR2 或 RAW 列长度影响如何在内部存储列。

•声明列长度为 4000 字节或更少的 VARCHAR2 和 NVARCHAR2 列以及声明列长度为 2000 字节或更少的 RAW 列在行内存储。

•声明列长度大于 4000 字节的 VARCHAR2 和 NVARCHAR2 列以及声明列长度大于 2000 字节的 RAW 列称为“扩展字符数据类型列”,它们在行外存储。

MAX_STRING_SIZE控制 SQL 中扩展数据类型的最大大小:

• STANDARD 表示在 Oracle 12c 之前使用的数据类型长度限制。

• EXTENDED 表示 Oracle Database 12c 中的 32767 字节限制。

扩展字符数据类型具有以下限制:

•在聚簇表和按索引组织的表中不受支持。

•没有分区内并行 DDL 、 UPDATE 和 DELETE DML 。

•对于在使用自动段空间管理 (Automatic Segment Space Management,ASSM) 进行管理的表空间中存储的表,没有分区内并行直接路径插入。

对比 LOB 数据类型,在 ASSM 表空间管理中,扩展数据类型的字段以 SecureFiles LOB 加以存储,而在非 ASSM 表空间管理中,它们则是以 BasciFiles LOB 进行存储的。

注意点:

Ø 不能将值从EXTENDED更改为 STANDARD 。 The only way to revert is to restore the database from backup prior to running the conversion script, $ORACLE_HOME/rdbms/admin/utl32k.sql

Ø 在RAC环境中,要关闭所有实例。只有将数据库实例参数 MAX_STRING_SIZE 设置为 EXTENDED 后,才能创建包含扩展字符数据类型列的表。 RAC 环境中所有 RAC 节点上 MAX_STRING_SIZE 初始化参数的值也必须相同。

Ø 需要特别注意的是:

①  Oracle 12c中的扩展的数据类型只是针对 非CDBPDB 而言的,而 CDB的根容器不支持扩展的数据类型 ,即使在根容器中修改成功也不能在CDB的根容器中创建超过 4000 字节的列。

②  从Oracle 12.2版本开始,可以在不修改 MAX_STRING_SIZE 参数的情况下创建最大 32767 字节的列,但是,实际最大存储依然是 4000 字节。所以,要想真正支持扩展数据类型,那么必须修改 MAX_STRING_SIZE 参数,而且运行相关脚本 utl32k.sql 和 utlrp.sql 。

与早期版本相比,诸如 VARCHAR2, NAVARCHAR2 这些数据类型的大小会从 4K 字节扩展至 32K 数据类型的使用。为了启用扩展字符大小,你必须将 MAX_STRING_SIZE 。

要使用扩展字符类型需要执行以下过程:
1.关闭数据库
2.以升级模式重启数据库
3.更改参数: ALTER SYSTEM SET MAX_STRING_SIZE=EXTENDED;
4.执行 utl32k.sql as sysdba :SQL> @?/rdbms/admin/utl32k.sql
5.关闭数据库
6.以读写模式重启数据库

varcha2、nvarchar2和raw字段的定义长度将影响字段的内部存储方式

  • STANDARD 代表12c之前的长度限制,即varchar2、nvarchar2 4000 bytes, raw 是2000 bytes

  • EXTENDED 代表12c 32k strings新特性,varchar2、nvarchar2、raw最大长度32k bytes

Extended character data types 扩展字符类型存在以下的限制:

    1. c , you can specify a maximum size of 32767 bytes for the VARCHAR2 , NVARCHAR2 , and RAW data types. You can control whether your database supports this new maximum size by setting the initialization parameter MAX_STRING_SIZE as follows:

      • If MAX_STRING_SIZE = STANDARD , then the size limits for releases prior to Oracle Database 12 Oracle Database Reference for complete information on the implications of this parameter and how to set and enable this new functionality.

A VARCHAR2 or NVARCHAR2 data type with a declared size of greater than 4000 bytes, or a RAW data type with a declared size of greater than 2000 bytes, is an data Oracle Database SecureFiles and Large Objects Developer's Guide for more information.

Note that, although you must set MAX_STRING_SIZE = EXTENDED in order to set the size of a RAW data type to greater than 2000 bytes, a RAW data type is stored as an out-of-line LOB only if it has a size of greater than 4000 bytes. For example, you must set MAX_STRING_SIZE = EXTENDED in order to declare a RAW(3000) data type. However, the column is stored inline.

You can use extended data types just as you would standard data types, with the following considerations:

  • For special considerations when creating an index on an extended data type column, or when requiring an index to enforce a primary key or unique constraint, see "Creating an Index on an Extended Data Type Column" .

  • If the partitioning key column for a list partition is an extended data type column, then the list of values that you want to specify for a partition may exceed the 4K byte limit for the partition bounds. See the size [ BYTE | CHAR ])

    Variable-length character string having maximum length size for VARCHAR2 . Minimum size )Variable-length Unicode character string having maximum length size for NVARCHAR2 . The number of bytes can be up to two times size for UTF8 encoding. Maximum p [, p and scale p can range from 1 to 38. The scale p )]A subtype of the NUMBER data type having precision p can range from 1 to 126 binary digits. A FLOAT value requires from 1 to 22 bytes.
    8LONGCharacter data of variable length up to 2 gigabytes, or 2 31 -1 bytes. Provided for backward compatibility.
    12DATEValid date range from January 1, 4712 BC, to December 31, 9999 AD. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is fixed at 7 bytes. This data type contains the datetime fields YEAR , MONTH , DAY , HOUR , MINUTE , and SECOND . It does not have fractional seconds or a time zone.
    100BINARY_FLOAT32-bit floating point number. This data type requires 4 bytes.
    101BINARY_DOUBLE64-bit floating point number. This data type requires 8 bytes.
    180TIMESTAMP [( fractional_seconds_precision is the number of digits in the fractional part of the SECOND datetime field. Accepted values of fractional_seconds_precision )] WITH TIME ZONEAll values of TIMESTAMP as well as time zone displacement value, where fractional_seconds_precision )] WITH LOCAL TIME ZONEAll values of TIMESTAMP WITH TIME ZONE , with the following exceptions:Data is normalized to the database time zone when it is stored in the database.When the data is retrieved, users see the data in the session time zone.The default format is determined explicitly by the NLS_TIMESTAMP_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is 7 or 11 bytes, depending on the precision.
    182INTERVAL YEAR [( year_precision is the number of digits in the YEAR datetime field. Accepted values are 0 to 9. The default is 2. The size is fixed at 5 bytes.
    183INTERVAL DAY [( fractional_seconds_precision )]Stores a period of time in days, hours, minutes, and seconds, wherefractional_seconds_precision is the number of digits in the fractional part of the SECOND field. Accepted values are 0 to 9. The default is 6.The size is fixed at 11 bytes.
    23RAW ( size bytes. You must specify size is:32767 bytes if MAX_STRING_SIZE = EXTENDED2000 bytes if MAX_STRING_SIZE = STANDARDRefer to "Extended Data Types" for more information on the MAX_STRING_SIZE initialization parameter.
    24LONG RAWRaw binary data of variable length up to 2 gigabytes.
    69ROWIDBase 64 string representing the unique address of a row in its table. This data type is primarily for values returned by the ROWID pseudocolumn.
    208UROWID [( size is the size of a column of type UROWID . The maximum size and default is 4000 bytes.
    96CHAR [( size bytes or characters. Maximum size is 1 byte.BYTE and CHAR have the same semantics as for VARCHAR2 .
    96NCHAR [( size characters. The number of bytes can be up to two times size for UTF8 encoding. Maximum size is 1 character.
    112CLOBA character large object containing single-byte or multibyte characters. Both fixed-width and variable-width character sets are supported, both using the database character set. Maximum size is (4 gigabytes - 1) * (database block size).
    112NCLOBA character large object containing Unicode characters. Both fixed-width and variable-width character sets are supported, both using the database national character set. Maximum size is (4 gigabytes - 1) * (database block size). Stores national character set data.
    113BLOBA binary large object. Maximum size is (4 gigabytes - 1) * (database block size).
    114BFILEContains a locator to a large binary file stored outside the database. Enables byte stream I/O access to external LOBs residing on the database server. Maximum size is 4 gigabytes.

    MAX_STRING_SIZE


    PropertyDescription
    SyntaxMAX_STRING_SIZE = { STANDARD | EXTENDED }
    ModifiableALTER SYSTEM ... SID='*' Foot 1
    BasicNo
    c apply (for example, 4000 bytes for VARCHAR 2 and NVARCHAR2 , and 2000 bytes for RAW ).EXTENDED means that the 32767 byte limit introduced in Oracle Database 12 pdb-name OPEN UPGRADE;
  • Change the setting of MAX_STRING_SIZE in the PDB to EXTENDED .

  • Run the rdbms/admin/utl32k.sql script in the PDB. You must be connected AS SYSDBA to run the utl32k.sql script.

  • Reopen the PDB in NORMAL mode.

    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.

  • Run the rdbms/admin/utlrp.sql script in the PDB to recompile invalid objects. You must be connected AS SYSDBA to run the script.

  • See Also:

  • Oracle Database Globalization Support Guide for more information about the MAX_STRING_SIZE parameter

  • \1. 关闭数据库

  • \2. 启动数据库到升级模式

  • \3. 修改max_string_size为EXTENDED,默认是standard

  • \4. 使用SYS用户执行脚本

  • \5. 重新启动数据库

  • SYS@OCM12C >startup

  • SYS@OCM12C >create table t3(blog varchar2(4001)) tablespace users;

  • SYS@OCM12C >create table t4(blog varchar2(32727)) tablespace users;

  • \1. 关闭PDB数据库

  • SYS@cdb > show pdbs;


  • 3 PDB1 READ WRITE NO

  • Pluggable database altered.

    本人提供Oracle、MySQL、PG等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!
  • SYS@cdb > alter pluggable database pdb1 open upgrade;

  • \3. 修改max_string_size参数为extended

  • System altered.

  • SYS@cdb > @?/rdbms/admin/utl32k.sql

  • ...Database user "SYS", database schema "APEX_040200", user# "98" 10:49:54

  • ...263 packages

  • ...453 tables

  • ...16 procedures

  • ...458 triggers

  • ...207 views

  • ...6 types

  • ...0 operators

  • ...Begin key object existence check 10:49:54

  • ...Setting DBMS Registry 10:49:54

  • ...Exiting validate 10:49:54

  • \5. 重新启动PDB数据库

  • Pluggable database altered.

  • Pluggable database altered.

  • SYS@cdb > create table t1(blog varchar2(32727)) tablespace users;

  • 常见错误:ORA-14696: MAX_STRING_SIZE migration is incomplete for pluggable database

  • 如果将CDB执行以上操作,会在执行完脚本rdbms/admin/utl32k.sql后重新启动数据库报错。

  • ORACLE instance started.

  • Fixed Size 2288728 bytes

  • Database Buffers 603979776 bytes

  • Database mounted.

  • ORA-14696: MAX_STRING_SIZE migration is incomplete for pluggable database

  • Process ID: 20105

  • 这段报错的意识是说CDB数据库已经是migrate状态了(startup upgrade),但是PDB$SEED还不是。需要对PDB$SEED做写操作。

  • SYS@cdb > startup mount;

  • 我们需要PDB$SEED处于MIGRATE状态

  • CON_ID NAME OPEN_MODE

  • 2 PDB$SEED MIGRATE

  • SYS@cdb > alter session set container=pdb$seed;

  • SYS@cdb > alter system set max_string_size = extended scope=both;

  • 当PDB$SEED处理结束后,接下来可以继续做PBD的扩展

  • SYS@cdb > alter pluggable database pdb1 open upgrade;

  • SYS@cdb > @?/rdbms/admin/utl32k.sql

  • SYS@cdb > alter pluggable database open;

标签:

头像

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

1 × 3 =

 

嘿,我是小麦,需要帮助随时找我哦
  • 18509239930
  • 个人微信

  • 麦老师QQ聊天
  • 个人邮箱
  • 点击加入QQ群
  • 个人微店

  • 回到顶部
返回顶部