Oracle JSON 使用连字符键查询

Oracle JSON Query with hyphen-key

我有一个版本为 12.1.0.2.0 的 Oracle 数据库和 JSON 我想查询的字段。

此查询有效:

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$."de"') from DUAL

本次查询returns错误ORA-40442.

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$."-"') from DUAL

连字符的查询在 MySQL 和 MSSQL 中没有问题。

我无法更改 JSON 字符串。

如何查询连字符?

解决方案是使用 unicode 表示:

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$."\u002d"') from DUAL

两者

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$."de"') from DUAL

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$."-"') from DUAL

有效

除非 JSON-path-expression 包含未加引号的非字母数字字符,例如:

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$.-') from DUAL

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$.d-e') from DUAL

不起作用和return错误ORA-40442

但是

select JSON_VALUE('{"-": "hello", "de":"hallo"}','$.de') from DUAL

工作没有问题,即使它没有被引用。

Demo