Oracle 12c 对Json数据的支持

Oracle 12.1.0.2的版本增加了一个新的功能,就是可以存储、查询JSON数据格式,而且也实现了使用SQL语句来解析JSON。以下是来自己文档的的一个示例:

创建一个带有校验JSON数据的一个clob字段的表

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));

INSERT INTO j_purchaseorder
  VALUES (
    SYS_GUID(),
    SYSTIMESTAMP,
    '{"PONumber"             : 1600,
      "Reference"            : "ABULL-20140421",
      "Requestor"            : "Alexis Bull",
      "User"                 : "ABULL",
      "CostCenter"           : "A50",
      "ShippingInstructions" : {"name"   : "Alexis Bull",
                                "Address": {"street"  : "200 Sporting Green",
                                            "city"    : "South San Francisco",
                                            "state"   : "CA",
                                            "zipCode" : 99236,
                                            "country" : "United States of America"},
                                "Phone" : [{"type" : "Office", "number" : "909-555-7307"},
                                           {"type" : "Mobile", "number" : "415-555-1234"}]},
      "Special Instructions" : null,
      "AllowPartialShipment" : true,
      "LineItems"            : [{"ItemNumber" : 1,
                                 "Part"       : {"Description" : "One Magic Christmas",
                                                 "UnitPrice"   : 19.95,
                                                 "UPCCode"     : 13131092899},
                                 "Quantity"   : 9.0},
                                {"ItemNumber" : 2,
                                 "Part"       : {"Description" : "Lethal Weapon",
                                                 "UnitPrice"   : 19.95,
                                                 "UPCCode"     : 85391628927},
                                 "Quantity"   : 5.0}]}');

查询 json 字段

SELECT po.po_document.PONumber FROM j_purchaseorder po;

PONUMBER
--------------------------------------------------------------------------------
1600


SELECT po.po_document.ShippingInstructions.Phone FROM j_purchaseorder po;

SHIPPINGINSTRUCTIONS
--------------------------------------------------------------------------------
[{"type":"Office","number":"909-555-7307"},{"type":"Mobile","number":"415-555-12
34"}]


SELECT po.po_document.ShippingInstructions.Phone.type FROM j_purchaseorder po;

SHIPPINGINSTRUCTIONS
--------------------------------------------------------------------------------
[Office,Mobile]
发布了303 篇原创文章 · 获赞 36 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/Hehuyi_In/article/details/105444289