CREATE OR REPLACE TYPE json_record_type
AS
OBJECT
(
id NUMBER,
name VARCHAR2(50),
` age NUMBER );
CREATE OR REPLACE TYPE json_table_type
AS
TABLE OF json_record_type;
;
DECLARE
json_data CLOB := '{ "data": [ {"id": 1, "name": "John", "age": 30}, {"id": 2, "name": "Alice", "age": 25} ] }';
json_obj json_table_type;
BEGIN
SELECT * BULK COLLECT
INTO json_obj
FROM JSON_TABLE(json_data, '$.data[*]' COLUMNS ( ID NUMBER PATH '$.id', name VARCHAR2(50) PATH '$.name', age NUMBER PATH '$.age' ) );
FOR i IN 1..json_obj.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE('ID: ' || json_obj(i).id || ', Name: ' || json_obj(i).name || ', Age: ' || json_obj(i).age);
END LOOP;
END;
'
1条答案
按热度按时间qni6mghb1#
给定您的类型(不包括随机附加字符):
将对象的示例(包含值)大容量收集到集合中:
其输出:
fiddle