在 Oracle 中通过 SQL 查询更改 JSON 层次结构

时间:2021-01-21 12:26:39

标签: sql json database oracle clob

我有一个包含 JSON 的 clob 表。 JSON 已经存在,我需要更改第一个值的层次结构。

这是原始的json:

{
  "configurationByAssetType" :
  {
    "default" :
    {
      "sections" :
      [
....
]
}}}

我需要将 configurationByAssetType 放在新部分 - configurationByView 下:

{
"configurationByView"
{
 "default" :{
  "configurationByAssetType" :
  {
    "default" :
    {
      "sections" :
      [
....
]
}}}}}

我想将所有现有数据复制到:

{
"configurationByView"
{
 "default" :{

1 个答案:

答案 0 :(得分:1)

为什么不将必要的字符连接到 clob 的开头和结尾:

with q as
 (select to_clob('{  "configurationByAssetType" :
                {
                  "default" :
                  {
                    "sections" :
                    [
              ....
              ]
              }}}') clob_json
from dual) 
select '{
"configurationByView"
    {
  "default" :{' || clob_json || '}}}'
  from q;
相关问题