如何在oracle中编写查询以从json列表中获取单个值作为字符串?

时间:2016-06-06 11:03:33

标签: sql json oracle

我有一个包含数据列表的json字符串,我想编写一个查询来根据条件获取单个值。但它正在返回值列表。请帮我在oracle数据库中编写一个有效的查询。

我的json字符串看起来像

[
{
  "Key": [
    {
      "obj": {
        "xyz":"cdf"
      },
      "Info": [
        {
          "Code": "",
          "tax": "",
          "rate": "",
          "taxAmount": {
            "formattedAmount": "",
            "Amount": ""
          }
        },
        {
          "Code": "qwer",
          "tax": "ggs",
          "rate": "0",
          "taxAmount": {
            "formattedAmount": "10.00",
            "Amount": "10.00"
          },
          "key": "qwer"
        },
        {
          "Code": "poiu",
          "tax": "ggs",
          "rate": "0",
          "taxAmount": {
            "formattedAmount": "20.00",
            "Amount": "20.00"
          },
          "key": "poiu"
        },
        {
          "coverageCode": "zxcv",
          "tax": "ggs",
          "rate": "0",
          "taxAmount": {
            "formattedAmount": "30.00",
            "Amount": "30.00"
          },
          "key": "zxcv"
        }
      ]
    },
    {
      "status": "S"
    }
  ]
}
]

我想获得formattedAmount值" 10.00"。写了一个像

这样的查询
SELECT json_query(details, '$.Info.taxAmount.formattedAmount' WITH WRAPPER) 
FROM details_table where json_query(details, '$.Info.Code' WITH WRAPPER) = 'qwer';

不返回任何值。如果没有where子句,我将获得列表中所有格式化的阿蒙特[," 10.00"," 20.00"," 30.00"]

0 个答案:

没有答案