I have an array in json, I want to write it in the oracle method post.But I have somewhere the error I can not find it. I try to write it all in a loop, the code compiles but does not write. The first thing I do is look for the first object using a loop. And then I use another loop in the middle of the object to record the data inside it!
v_clob := iot_general.blob_to_clob(p_blob);
apex_json.parse(tv, v_clob);
sCount := APEX_JSON.get_count(p_path => 'GroupSensor' , p_values => tv);
IF sCount > 0 THEN
FOR i in 1 .. sCount LOOP
v_id := apex_json.get_varchar2(p_path => 'GroupSensor.SerialNumber['|| i ||']', p_values => tv);
cCount := APEX_JSON.get_count(p_path => 'GroupSensor.GroupBob['|| i ||']' , p_values => tv);
IF cCount > 0 THEN
FOR q in 1 .. cCount LOOP
q_temp := apex_json.get_varchar2(p_path => 'GroupSensor.GroupBob['|| i ||']['|| q ||']', p_values => tv);
INSERT INTO SILO_SENSOR( NAME, DEVICES_ID)
VALUES (q_temp,v_id );
commit;
END LOOP;
END IF;
END LOOP;
END IF;
Here is my json
{
"GroupSensor": [
{
"silos": 1,
"GroupBob": [
"SENSOR0001",
"SENSOR0002",
"SENSOR0003",
"SENSOR0004",
"SENSOR0005",
"SENSOR0006",
"SENSOR0007",
"SENSOR0008",
"SENSOR0009",
"SENSOR0010"
],
"SerialNumber": "1701"
},
{
"silos": 1,
"GroupBob": [
"SENSOR0011",
"SENSOR0012",
"SENSOR0013",
"SENSOR0014",
"SENSOR0015",
"SENSOR0016",
"SENSOR0017",
"SENSOR0018",
"SENSOR0019"
],
"SerialNumber": "1702"
},
{
"silos": 1,
"GroupBob": [
"SENSOR0020",
"SENSOR0021",
"SENSOR0022",
"SENSOR0023",
"SENSOR0024",
"SENSOR0025",
"SENSOR0026",
"SENSOR0027",
"SENSOR0028"
],
"SerialNumber": "1703"
}
]
}
I want to write the data to the SILO_SENSOR table, that's it
NAME DEVICES_ID
SENSOR0001 1701
SENSOR0002 1701
SENSOR0003 1701
SENSOR0004 1701
SENSOR0005 1701
SENSOR0006 1701
SENSOR0007 1701
SENSOR0008 1701
SENSOR0009 1701
SENSOR0010 1701