1:创建一个带有表,里面包含存储JSON数据的字段类型比如CLOB,而且需要对输入JSON的验证限制
- [oracle@oracle12c ~]$ sqlplus sde/sde@pdborcl
-
- SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 30 05:19:34 2014
-
- Copyright (c) 1982, 2014, Oracle. All rights reserved.
-
- Last Successful login time: Tue Jul 29 2014 09:47:20 -04:00
-
- Connected to:
- Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
- With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
-
- SQL> CREATE TABLE j_purchaseorder
- (id RAW (16) NOT NULL,
- date_loaded TIMESTAMP WITH TIME ZONE,
- po_document CLOB
- CONSTRAINT ensure_json CHECK (po_document IS JSON)); 2 3 4 5
-
- Table created.
[oracle@oracle12c ~]$ sqlplus sde/sde@pdborcl
SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 30 05:19:34 2014
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Last Successful login time: Tue Jul 29 2014 09:47:20 -04:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> CREATE TABLE j_purchaseorder
(id RAW (16) NOT NULL,
date_loaded TIMESTAMP WITH TIME ZONE,
po_document CLOB
CONSTRAINT ensure_json CHECK (po_document IS JSON)); 2 3 4 5
Table created.
2:插入带有JSON数据的一条记录
- SQL> INSERT INTO j_purchaseorder
- 2 VALUES (SYS_GUID(),
- 3 SYSTIMESTAMP,
- 4 '{ "PONumber" : 1600,
- 5 "Reference" : "ABULL-20140421",
- 6 "Requestor" : "Alexis Bull",
- 7 "User" : "ABULL",
- 8 "CostCenter" : "A50",
- 9 "ShippingInstructions" : { "name" : "Alexis Bull",
- 10 "Address": { "street" : "200 Sporting Green",
- 11 "city" : "South San Francisco",
- 12 "state" : "CA",
- 13 "zipCode" : 99236,
- 14 "country" : "United States of America" },
- 15 "Phone" : [ { "type" : "Office", "number" : "909-555-7307" },
- { "type" : "Mobile", "number" : "415-555-1234" } ] },
- 16 17 "Special Instructions" : null,
- 18 "AllowPartialShipment" : false,
- 19 "LineItems" : [ { "ItemNumber" : 1,
- 20 "Part" : { "Description" : "One Magic Christmas",
- 21 "UnitPrice" : 19.95,
- 22 "UPCCode" : 13131092899 },
- 23 "Quantity" : 9.0 },
- 24 { "ItemNumber" : 2,
- 25 "Part" : { "Description" : "Lethal Weapon",
- 26 "UnitPrice" : 19.95,
- 27 "UPCCode" : 85391628927 },
- 28 "Quantity" : 5.0 } ] }');
-
- 1 row created.
SQL> INSERT INTO j_purchaseorder
2 VALUES (SYS_GUID(),
3 SYSTIMESTAMP,
4 '{ "PONumber" : 1600,
5 "Reference" : "ABULL-20140421",
6 "Requestor" : "Alexis Bull",
7 "User" : "ABULL",
8 "CostCenter" : "A50",
9 "ShippingInstructions" : { "name" : "Alexis Bull",
10 "Address": { "street" : "200 Sporting Green",
11 "city" : "South San Francisco",
12 "state" : "CA",
13 "zipCode" : 99236,
14 "country" : "United States of America" },
15 "Phone" : [ { "type" : "Office", "number" : "909-555-7307" },
{ "type" : "Mobile", "number" : "415-555-1234" } ] },
16 17 "Special Instructions" : null,
18 "AllowPartialShipment" : false,
19 "LineItems" : [ { "ItemNumber" : 1,
20 "Part" : { "Description" : "One Magic Christmas",
21 "UnitPrice" : 19.95,
22 "UPCCode" : 13131092899 },
23 "Quantity" : 9.0 },
24 { "ItemNumber" : 2,
25 "Part" : { "Description" : "Lethal Weapon",
26 "UnitPrice" : 19.95,
27 "UPCCode" : 85391628927 },
28 "Quantity" : 5.0 } ] }');
1 row created.