【问题标题】:Split json field to extract value in oracle sql拆分json字段以提取oracle sql中的值
【发布时间】:2022-07-01 00:03:43
【问题描述】:

我有一个带有 varchar2 类型字段的表,其中保存了类似这样的“json”:

json data{
     first:one
     second:two
}

上例中出现的字符串“json”也保存在字段中。

我需要一个带出值“一”、“二”的查询。 你能帮帮我吗?

【问题讨论】:

  • 那不是有效的 JSON。键或字符串文字周围没有引号,键值对之间没有逗号。

标签: sql json oracle varchar2


【解决方案1】:

在Oracle中这个带有表和数据字段的sql语句:

--couple
select regexp_substr(data, '\S+', 1, 3) as item1 from table;
select regexp_substr(data, '\S+', 1, 4) as item2 from table;

--values
select regexp_substr(regexp_substr(data, '\S+', 1, 3), '[^:]+', 1, 2) as value1 from table;
select regexp_substr(regexp_substr(data, '\S+', 1, 4), '[^:]+', 1, 2) as value2 from table;

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 2023-01-26
    • 2021-12-21
    • 2015-08-22
    • 2015-05-13
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多