vlambda博客
学习文章列表

数据库21c的JSON数据类型

     Oracle Database 21c 数据库的 JSON 数据类型验证测试。

     JSON数据类型从Oracle Database 12c开始引入。JSON数据类型最开始以VARCHAR2或者CLOB的数据类型,配合CHECK约束来实现。


目前从21c开始,直接有JSON数据类型支持。几个基本特性如下:

1、You can use the  JSON data type to store JSON data natively in binary format. This improves query performance because textual JSON data no longer needs to be parsed. 

(可以使用JSON数据类型以二进制格式本地存储JSON数据。这提高了查询性能,因为不再需要解析文本JSON数据。)


2、You can create JSON type instances from other SQL data, and conversely.

(您可以从其他SQL数据创建JSON类型的实例,反之亦然。)


3、You must set the database initialization parameter  compatible to  20 in order to use the new JSON data type.

(为了使用新的JSON数据类型,必须将数据库初始化参数compatible设置为20。)


4、The other SQL data types that support JSON data, besides  JSON type, are  VARCHAR2 ,  CLOB ,and  BLOB . Non-JSON type data is called textual, or serialized, JSON data. It is unparsed character data.

(除了JSON类型之外,支持JSON数据的其他SQL数据类型还有VARCHAR2、CLOB和BLOB。非JSON类型的数据称为文本或序列化的JSON数据。这是无与伦比的字符数据。)


5、You can use the  JSON constructor function to convert textual JSON data to  JSON type data.

(可以使用JSON构造函数将文本JSON数据转换为JSON类型的数据。)


6、To convert  JSON type data to textual data, you can use the  JSON_SERIALIZE function.

(要将JSON类型的数据转换为文本数据,可以使用JSON_SERIALIZE函数。)


7、You can create complex  JSON type data from non- JSON type data using the JSON generation functions:  JSON_OBJECT ,  JSON_ARRAY ,  JSON_OBJECTAGG , and  JSON_ARRAYAGG .

(您可以使用JSON生成函数从非JSON类型的数据创建复杂的JSON类型数据:JSON_OBJECT 、JSON_ARRAY、JSON_OBJECTAGG和JSON_ARRAYAGG。)


8、You can create a  JSON type instance with a scalar JSON value using the function JSON_SCALAR .

(可以使用函数JSON_scalar创建带有标量JSON值的JSON类型实例。)


9、In the other direction, you can use the function  JSON_VALUE to query  JSON type data and return an instance of a SQL object type or collection type.

(另一方面,可以使用函数JSON_VALUE查询JSON类型的数据,并返回SQL对象类型或集合类型的实例。)


下面看看简单的使用测试:

  • 创建和查看JSON类型的表:


  • 向JSON类型的表插入数据:

数据库21c的JSON数据类型


  • 从JSON类型的表查询数据:注意看报错

数据库21c的JSON数据类型


  • 从JSON类型的表查询数据:注意看报错和解决方法

数据库21c的JSON数据类型


  • 从JSON类型的表查询JSON数据完整内容

数据库21c的JSON数据类型


  • 从JSON类型的表查询JSON数据完整内容


以上是简单的测试和验证。详细的内容可以参考官方手册《json-developers-guide.pdf》。