json - plsql 代码在不使用第三方库的情况下解析 JSON
问题描述
JSON 需要仅使用 PL/SQL 代码(如正则表达式)进行解析,以从中获取sentiment
值confidence
。
类似的东西
[
{
"sentiment":"negative",
"confidence":0.6211975044276729
},
{
"sentiment":"neutral",
"confidence":0.3510681601407111
},
{
"sentiment":"positive",
"confidence":0.027734335431616075
}
]
上面的 JSON 需要被解析才能从中获取sentiment
和confidence
取值
解决方案
JSON_TABLE函数从 Oracle Database 12c 第 1 版 (12.1.0.2) 开始可用。
SET NUMWIDTH 20 --Use this if SQL*Plus/ SQL developer truncates digits.
--test data
WITH t ( json_col ) AS ( SELECT '[
{
"sentiment":"negative",
"confidence":0.6211975044276729
},
{
"sentiment":"neutral",
"confidence":0.3510681601407111
},
{
"sentiment":"positive",
"confidence":0.027734335431616075
}
]'
FROM dual
) --test data ends
SELECT j.*
FROM t
CROSS JOIN
JSON_TABLE ( json_col,'$[*]'
COLUMNS (
sentiment VARCHAR2(20) PATH '$.sentiment',
confidence NUMBER PATH '$.confidence'
)
)
j;
SENTIMENT CONFIDENCE
-------------------- --------------------
negative .6211975044276729
neutral .3510681601407111
positive .027734335431616075
推荐阅读
- node.js - Firebase Firestore 增量字段值不增加
- javascript - 当服务器停止而Firefox浏览器可以播放时,chrome不会播放视频文件
- swift - 空白 UIActivityViewController Swift 5
- mongodb - POST 用户信息从前端到 MongoDB 后端 React-Native, MongoDB
- java - 使用 charset x-IBM300 解码数据会为不同 JVM 上的不可映射代码点提供不同的结果
- javascript - Discord.js 机器人审计日志问题 (v12)
- r - 从字符向量中删除特定字符串或空白成员
- java - apache spark:添加JVM参数
- c - 从文本文件中提取双引号内的值
- java - Spring Boot Jackson ResponseEntity 找不到类的序列化程序