我试图获取 LineNumber 的值,但收到错误消息
ORA-31013: Invalid XPATH expression 31013. 00000 - "Invalid XPATH expression" *Cause: XPATH expression passed to the function is invalid. *Action: Check the xpath expression for possible syntax errors.
似乎json格式不起作用,Oracle不认为lines.x是一个json字符串。
select JSON_value(aaa.af1, '$.a.System.Publisher')
, lines.x
, JSON_value(lines.x, '$.LineNumber')
from (
select '{"a":{"System": {"Publisher":"dms_WarehouseExpectedReceipt"},"WarehouseCode":"WHSE1","LineItem":[{"LineNumber":1000,"ItemNumber":"P00001","PackageCode":"*","Lot":"","Gtin":"70000100000015","ExpectedDate":"2018-12-13 12:00:00","InventoryAttributes":{"Character1":"","Character2":"","Character3":""}}]}}' af1 from dual
) aaa
cross apply
json_table(aaa.af1, '$.a.LineItem[*]'
COLUMNS(
queue_child_seq for ordinality
, x format json path '$'
)
) lines
谢谢。
最佳答案
有趣。此查询似乎在 Oracle 18c 中运行得很好,但当我在本地(Oracle 12c 企业版版本 12.2.0.1.0)中测试时,会抛出相同的错误。
我对此并不完全确定,但似乎 JSON_value
期望数据类型是提取的 JSON 字符串的 CLOB
,因此错误具体来自 JSON_value (lines.x,'$.LineNumber')
。
我能想到的唯一解决方法是使用TO_CLOB
将lines.x
显式转换为CLOB
,这对我来说很有用12.2版本。
JSON_value(TO_CLOB(lines.x), '$.LineNumber')
关于json - Oracle中如何使用json格式获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53782668/