【问题标题】:How to filter json in PLSQL?如何在 PLSQL 中过滤 json?
【发布时间】:2020-12-14 10:18:14
【问题描述】:

我的数据如下:

CLUID                       EVENT_PAYLOAD                                                       STEP    
1998-06-22-23.58.16.792243  {"type":"page","name":"currentAccount/88095C45B7E1D68346905AA7B791F731D7F94715/new-transfer","source":"currentAccount/:id/new-transfer","data":{}}  currentAccount/:id/new-transfer
1997-08-25-18.52.07.994112  {"type":"page","name":"orders/sign/200831527425199","source":"orders/sign(/:orderIds)","data":{}}   orders/sign(/:orderIds)
2000-05-09-20.49.42.573031  {"type":"page","name":"currentAccount/33BF3B031E71719AD30C34588B5832CA8F1EC2D1/orders","source":"currentAccount/:id/orders","data":{}}  currentAccount/:id/orders
1998-07-21-20.50.04.641225  {"type":"event","name":"logout","source":"currentAccount/F2A81A2D982AD8D736E5461808CF8C33FDDC9EEC/transactions","data":{"category":"session","normalized":"currentAccount/:id/transactions","eventValue1":"manual"}}    logout

我只想选择 EVENT_PAYLOAD 类型为“页面”的数据。

我写过:

 SELECT CLUID, STEP--, b.type
 FROM VDS_OWNER.PROTO_BEAN_COUNTER_EVENTS_BASE2
 WHERE (JSON_TABLE(EVENT_PAYLOAD, '$'
                        COLUMNS (type VARCHAR2 PATH '$."type"')
                        )
        ) = 'page'

我们将不胜感激。 谢谢!

【问题讨论】:

    标签: sql json oracle plsql


    【解决方案1】:

    如果你已经正确声明了 JSON 列,你可以使用点符号来按键访问 JSON 值:

    select cluid, step, e.event_payload.type
    from VDS_OWNER.PROTO_BEAN_COUNTER_EVENTS_BASE2 e
    where e.event_payload.type = 'page'
    

    或者,您可以使用json_value()

    select cluid, step, json_value(e.event_payload, '$.type') as type
    from mytable e
    where json_value(e.event_payload, '$.type') = 'page'
    

    Demo on DB Fiddle

    【讨论】:

      猜你喜欢
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 1970-01-01
      • 2017-11-24
      • 2017-01-25
      • 2019-08-17
      • 2020-11-14
      相关资源
      最近更新 更多