如何在 Oracle json_arrayagg 中添加虚拟记录
How to add dummy record in Oracle json_arrayagg
我有一个简单的 Oracle 数据库 table,有两列,有这个查询
select
json_object( key 'clientTypes' VALUE
(
select
json_arrayagg( json_object( key 'code' VALUE ct.code, key 'name' VALUE ct.name ) ORDER BY ct.code ASC )
from
CASINO.CLIENTTYPES ct
WHERE
ct.code != 'system'
)
returning clob ) responseJson
FROM
DUAL
结果是单列,CLOB 包含 JSON 个嵌套数组的对象
{
"list": [{
"code": 1,
"name": "abc"
},
{
"code": 2,
"name": "def"
}]
}
我需要在生成的 JSON 对象中添加单个虚拟记录,如下所示
{
"list": [{
"code": 1,
"name": "abc"
},
{
"code": 2,
"name": "def"
},
{ "code": dummy code,
"name": "dummy name"
}]
}
我建议您在进行 JSON 转换之前将所有虚拟数据联合起来
例如:
from CASINO.CLIENTTYPES ct
并做到
from (
select systemcode, code, name from casino.clienttypes
union all
select 'x', -1, 'dummy name' from dual
) ct
如果您希望代码显示 'dummy code',您需要对来自客户端类型 table 的实际数字代码执行 TO_CHAR,例如 TO_CHAR(code) as code
我有一个简单的 Oracle 数据库 table,有两列,有这个查询
select
json_object( key 'clientTypes' VALUE
(
select
json_arrayagg( json_object( key 'code' VALUE ct.code, key 'name' VALUE ct.name ) ORDER BY ct.code ASC )
from
CASINO.CLIENTTYPES ct
WHERE
ct.code != 'system'
)
returning clob ) responseJson
FROM
DUAL
结果是单列,CLOB 包含 JSON 个嵌套数组的对象
{
"list": [{
"code": 1,
"name": "abc"
},
{
"code": 2,
"name": "def"
}]
}
我需要在生成的 JSON 对象中添加单个虚拟记录,如下所示
{
"list": [{
"code": 1,
"name": "abc"
},
{
"code": 2,
"name": "def"
},
{ "code": dummy code,
"name": "dummy name"
}]
}
我建议您在进行 JSON 转换之前将所有虚拟数据联合起来
例如:
from CASINO.CLIENTTYPES ct
并做到
from (
select systemcode, code, name from casino.clienttypes
union all
select 'x', -1, 'dummy name' from dual
) ct
如果您希望代码显示 'dummy code',您需要对来自客户端类型 table 的实际数字代码执行 TO_CHAR,例如 TO_CHAR(code) as code