我想要在 json 中搜索文本。该 json 保留在 blob 字段中。我创建了下表
CREATE TABLE APPLICATION
(
applicationId VARCHAR2(36),
customerId VARCHAR2(36),
assignee VARCHAR2(36),
status VARCHAR2(36),
applicationDate TIMESTAMP,
closerDueDate TIMESTAMP,
closedDate TIMESTAMP,
application blob ,
CONSTRAINT application CHECK(application IS JSON FORMAT JSON)) LOB (application) STORE AS(STORAGE (NEXT 15M));
为了保留一行,我使用 SQL Develop UI 添加所有字段值并将 json 文件附加到 blob 字段中。 blob 字段中附加的文件具有 json 文本(巨大的 json)。文件示例
{
"fields" : {
"Customerid" : "Organization"
}
}
//Huge Json
我想使用路径在 blob 字段内搜索。喜欢:fields.Customerid:"Organization"
我正在使用跟随查询,但它没有得到任何行select *
from application app
where dbms_lob.instr(app.application, utl_raw.CAST_TO_RAW('AutomationRuleSet'), 1, 1) > 0;
我知道 json 中存在的值持久化编辑 1
如果我尝试:
Select app.application
From APPLICATION app
Where JSON_QUERY(app.application, '$.fields.CustomerID') = 'AutomationRuleSet';
我有:Error que empieza en la línea 1 del comando:
Select app.application From APPLICATION app Where JSON_QUERY(app.application, '$.fields.CustomerID') = 'AutomationRuleSet'
Error en la línea de comandos:2 Columna:6 Informe de error:
Error SQL: ORA-40499: no format defined for binary data type
有什么问题?
最佳答案
您可以使用 json_exists()
找到 JSON BLOBS 包含关键路径的行:
select * from application app
where json_exists(app.application, '$.fields.Customerid');
您可以使用
json_value()
搜索特定值:select * from application app
where json_value(app.application, '$.fields.Customerid') = 'AutomationRuleSet';
当您使用 BLOB 时,您可能需要指定
format json
,虽然我似乎不需要在 12.2 和你的表定义中测试这个:select * from application app
where json_exists(application format json, '$.fields.Customerid');
select * from application app
where json_value(application format json, '$.fields.Customerid') = 'AutomationRuleSet';
Oracle Live SQL demo .
关于sql - 如何使用 Oracle 12c 在 BLOB 字段中附加的 Json 文件中搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41491577/