Loading SODA Collections with SQL*Loader in Oracle Database 23ai/26ai
In Oracle 23ai/26ai we can use SQL*Loader to load JSON data into a Simple Oracle Document Access (SODA) collection.
oracle 23configurationintermediate
by OracleDba
16 views
In Oracle 23ai/26ai we can use SQL*Loader to load JSON data into a Simple Oracle Document Access (SODA) collection.
123456789101112131415161718192021222324252627282930313233343536
conn testuser1/testuser1@//localhost:1521/freepdb1
set long 1000000 pagesize 10000 trimspool on
spool /tmp/objects.json
select json_serialize(
json_array(select json_object('owner' : owner,
'object-name' : object_name,
'subobject-name' : subobject_name,
'object-id' : object_id)
from all_objects
where rownum <= 100
returning json
)
returning clob pretty) as output;
spool off
[
{
"owner" : "SYS",
"object-name" : "ORA$BASE",
"subobject-name" : null,
"object-id" : 138
},
... Edited for brevity
{
"owner" : "SYS",
"object-name" : "V_$HVMASTER_INFO",
"subobject-name" : null,
"object-id" : 2048
}
]12345678910111213141516171819202122232425262728
conn testuser1/testuser1@//localhost:1521/freepdb1
set serveroutput on
declare
l_collection soda_collection_t;
begin
l_collection := dbms_soda.create_collection('TestCollection1');
if l_collection is not null then
dbms_output.put_line('Collection ID : ' || l_collection.get_name());
else
dbms_output.put_line('Collection does not exist.');
end if;
end;
/
Collection ID : TestCollection1
PL/SQL procedure successfully completed.
SQL>
select count(*) from "TestCollection1";
COUNT(*)
----------
0
SQL>123456789
dnf install -y jq
cat /tmp/objects.json | jq -cr '.[]' > /tmp/objects2.json
{"owner":"SYS","object-name":"ORA$BASE","subobject-name":null,"object-id":138}
... Edited for brevity
{"owner":"SYS","object-name":"V_$HVMASTER_INFO","subobject-name":null,"object-id":2048}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
load data
infile '/tmp/objects2.json'
append
into collection TestCollection1
fields terminated by '0x02'
($CONTENT)
$ cd /tmp
$ sqlldr userid=testuser1/testuser1@//localhost:1521/freepdb1 \
control=/tmp/objects.ctl \
log=/tmp/objects.log
SQL*Loader: Release 23.0.0.0.0 - Developer-Release on Wed Apr 26 09:33:50 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle and/or its affiliates. All rights reserved.
Path used: SODA Collection
Commit point reached - logical record count 100
SODA Collection TestCollection1:
100 Rows successfully loaded.
Check the log file:
objects.log
for more information about the load.
$
$ cat /tmp/objects.log
SQL*Loader: Release 23.0.0.0.0 - Developer-Release on Wed Apr 26 09:53:59 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle and/or its affiliates. All rights reserved.
Path used: SODA Collection
Commit point reached - logical record count 100
SODA Collection TestCollection1:
100 Rows successfully loaded.
Check the log file:
/tmp/objects.log
for more information about the load.
[oracle@localhost tmp]$ cat /tmp/objects.log
SQL*Loader: Release 23.0.0.0.0 - Developer-Release on Wed Apr 26 09:53:59 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle and/or its affiliates. All rights reserved.
Control File: /tmp/objects.ctl
Data File: /tmp/objects2.json
Bad File: /tmp/objects2.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 250 rows, maximum of 1048576 bytes
Continuation: none specified
Path used: SODA Collection
SODA Collection TestCollection1, loaded from every logical record.
Insert option in effect for this SODA collection: APPEND
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
$CONTENT FIRST * CHARACTER
Terminator string : '0x02'
SODA Collection TestCollection1:
100 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 64500 bytes(250 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 100
Total logical records rejected: 0
Total logical records discarded: 0
Run began on Wed Apr 26 09:53:59 2023
Run ended on Wed Apr 26 09:53:59 2023
Elapsed time was: 00:00:00.10
CPU time was: 00:00:00.03
$
select count(*) from "TestCollection1";
COUNT(*)
----------
100
SQL>1234567891011121314
set serveroutout on
declare
l_status number := 0;
begin
l_status := dbms_soda.drop_collection('TestCollection1');
dbms_output.put_line('status : ' || l_status);
end;
/
status : 1
PL/SQL procedure successfully completed.
SQL>Please to add comments
No comments yet. Be the first to comment!