在 Oracle 19 上将 json 放入另一个 json 中
Put a json inside another json on Oracle 19
我有下一个问题。我需要从 table 创建一个 json,其中一列中包含另一个 json
有了这个:
CREATE TABLE BRUNOVS.TABLA_JSON_1
( COL CLOB COLLATE USING_NLS_COMP,
ID NUMBER,
NAME VARCHAR2(50 BYTE) COLLATE USING_NLS_COMP,
AGE NUMBER
)
insert into tabla_json_1 (col, ID, NAME, AGE) values (
'{"totalResults":1,"limit":100,"offset":0,"items":[{"customerId":"24929","schedule":{"2021-03-24":{"freeTime":[["09:00","09:30"],["11:00","18:00"]],"arrivalTime":[{"min":"09:30","max":"10:30"},{"min":"11:30","max":"16:30"}]}}}]}',
4, 'Clara', 40
);
commit;
我尝试使用此查询:
SELECT JSON_OBJECT (
'id' VALUE to_char(a.id),
'name' VALUE to_char(a.name),
'age' value to_char(a.age),
'original' value to_char(col)
)
FROM tabla_json_1 a
where a.id = 4;
但结果不正确:
{"id":"4","name":"Clara","age":"40","original":"{\"totalResults\":1,\"limit\":100,\"offset\":0,\"items\":[{\"customerId\":\"24929\",\"schedule\":{\"2021-03-24\":{\"freeTime\":[[\"09:00\",\"09:30\"],[\"11:00\",\"18:00\"]],\"arrivalTime\":[{\"min\":\"09:30\",\"max\":\"10:30\"},{\"min\":\"11:30\",\"max\":\"16:30\"}]}}}]}"}
必须是这样的:
{"id":"4","name":"Clara","age":"40","original":{"totalResults":1,"limit":100,"offset":0,"items":[{"customerId":"24929","schedule":{"2021-03-24":{"freeTime":[["09: 00","09: 30"],["11: 00","18: 00"]],"arrivalTime":[{"min":"09: 30","max":"10: 30"},{"min":"11: 30","max":"16: 30"}]}}}]}}
有办法得到正确的结果吗?
此致。
查看示例并查看结果。
我知道怎么做:
SELECT JSON_OBJECT (
'id' VALUE to_char(a.id),
'name' VALUE to_char(a.name),
'age' value to_char(a.age),
'original' value treat ( col as json ) -- this is the key
)
FROM tabla_json_1 a
where a.id = :agendamiento_id;
谢谢大家。
此致
我有下一个问题。我需要从 table 创建一个 json,其中一列中包含另一个 json 有了这个:
CREATE TABLE BRUNOVS.TABLA_JSON_1
( COL CLOB COLLATE USING_NLS_COMP,
ID NUMBER,
NAME VARCHAR2(50 BYTE) COLLATE USING_NLS_COMP,
AGE NUMBER
)
insert into tabla_json_1 (col, ID, NAME, AGE) values (
'{"totalResults":1,"limit":100,"offset":0,"items":[{"customerId":"24929","schedule":{"2021-03-24":{"freeTime":[["09:00","09:30"],["11:00","18:00"]],"arrivalTime":[{"min":"09:30","max":"10:30"},{"min":"11:30","max":"16:30"}]}}}]}',
4, 'Clara', 40
);
commit;
我尝试使用此查询:
SELECT JSON_OBJECT (
'id' VALUE to_char(a.id),
'name' VALUE to_char(a.name),
'age' value to_char(a.age),
'original' value to_char(col)
)
FROM tabla_json_1 a
where a.id = 4;
但结果不正确:
{"id":"4","name":"Clara","age":"40","original":"{\"totalResults\":1,\"limit\":100,\"offset\":0,\"items\":[{\"customerId\":\"24929\",\"schedule\":{\"2021-03-24\":{\"freeTime\":[[\"09:00\",\"09:30\"],[\"11:00\",\"18:00\"]],\"arrivalTime\":[{\"min\":\"09:30\",\"max\":\"10:30\"},{\"min\":\"11:30\",\"max\":\"16:30\"}]}}}]}"}
必须是这样的:
{"id":"4","name":"Clara","age":"40","original":{"totalResults":1,"limit":100,"offset":0,"items":[{"customerId":"24929","schedule":{"2021-03-24":{"freeTime":[["09: 00","09: 30"],["11: 00","18: 00"]],"arrivalTime":[{"min":"09: 30","max":"10: 30"},{"min":"11: 30","max":"16: 30"}]}}}]}}
有办法得到正确的结果吗?
此致。
查看示例并查看结果。 我知道怎么做:
SELECT JSON_OBJECT (
'id' VALUE to_char(a.id),
'name' VALUE to_char(a.name),
'age' value to_char(a.age),
'original' value treat ( col as json ) -- this is the key
)
FROM tabla_json_1 a
where a.id = :agendamiento_id;
谢谢大家。
此致