SQLcl : Simple Oracle Document Access (SODA) for SQLcl
This article gives an overview of the integration of Simple Oracle Document Access (SODA) in SQLcl.
oracle miscconfigurationintermediate
by OracleDba
14 views
This article gives an overview of the integration of Simple Oracle Document Access (SODA) in SQLcl.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
SQL> soda create TestCollection1;
Failed to execute: soda create TestCollection1
SQL>
SQL>
help soda
SODA
------
SODA allows schemaless application development using the JSON data model.
SODA create <collection_name>
Create a new collection
SODA list
List all the collections
SODA get <collection_name> [-all | -f | -k | -klist] [{<key> | <k1> <k2> ... > | <qbe>}]
List documents the collection
Optional arguments:
-all list the keys of all docs in the collection
-k list docs matching the specific <key>
-klist list docs matching the list of keys
-f list docs matching the <qbe>
SODA insert <collection_name> <json_str | filename>
Insert a new document within a collection
SODA drop <collection_name>
Delete existing collection
SODA count <collection_name> [<qbe>]
Count # of docs inside collection.
Optional <qbe> returns # of matching docs
SODA replace <collection_name> <oldkey> <new_{str|doc}>
Replace one doc for another
SODA remove <collection_name> [-k | -klist |-f] {<key> | <k1> <k2> ... | <qbe>}
Remove doc(s) from collection
Optional arguments:
-k remove doc in collection matching the specific <key>
-klist remove doc in collection matching the list <key1> <key2> ... >
-f remove doc in collection matching <qbe>
SQL>
-- Works
SODA list
soda list
-- Fails
soda LIST
soda List12345678910
CONN sys/SysPassword1@//localhost:1521/pdb1 AS SYSDBA
DROP USER sodauser CASCADE;
CREATE USER sodauser IDENTIFIED BY sodauser1
DEFAULT TABLESPACE users QUOTA UNLIMITED ON users;
GRANT CREATE SESSION, CREATE TABLE TO sodauser;
GRANT SODA_APP TO sodauser;
CONN sodauser/sodauser1@//localhost:1521/pdb112345678910111213141516171819202122
SQL>
soda create TestCollection1
Successfully created collection: TestCollection1
SQL>
DESC "TestCollection1"
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
ID NOT NULL VARCHAR2(255)
CREATED_ON NOT NULL TIMESTAMP(6)
LAST_MODIFIED NOT NULL TIMESTAMP(6)
VERSION NOT NULL VARCHAR2(255)
JSON_DOCUMENT BLOB
SQL>
SQL>
soda create TESTCOLLECTION1
Successfully created collection: TESTCOLLECTION1
SQL>12345678
SQL>
soda list
List of collections:
TESTCOLLECTION1
TestCollection1
SQL>12345678910111213141516171819202122232425262728
SQL> soda list
List of collections:
TESTCOLLECTION1
TestCollection1
SQL>
SQL>
soda drop TESTCOLLECTION1
Successfully dropped: TESTCOLLECTION1
SQL>
SQL> soda list
List of collections:
TestCollection1
SQL>
DESC "TESTCOLLECTION1"
ERROR:
ORA-04043: object "TESTCOLLECTION1" does not exist
SQL>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
{
"employees": [
{ "employee_number": 7369, "employee_name": "SMITH", "department_number": 20 },
{ "employee_number": 7499, "employee_name": "ALLEN", "department_number": 30 }
]
}
SQL> soda count TestCollection1
No matching records found.
SQL>
SQL>
soda insert TestCollection1 C:\temp\employees.json
Json String inserted successfully.
Successfully inserted file: C:\temp\employees.json
SQL>
SQL> soda count TestCollection1
1 row selected.
SQL>
SELECT COUNT(*) FROM "TestCollection1";
COUNT(*)
----------
1
1 row selected.
SQL>
SQL> soda count TestCollection1
1 row selected.
SQL>
SQL>
soda insert TestCollection1 {"fruit": "apple"}
Json String inserted successfully.
SQL>
SQL> soda count TestCollection1
2 rows selected.
SQL>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
SQL>
soda get TestCollection1 -all
KEY Created On
B58C675044F84408A8F058E71D1F38F1 2020-08-12T20:03:14.437315Z
45E8861FAF834353979DD74659B6E1E7 2020-08-12T20:03:52.907795Z
2 rows selected.
SQL>
SQL>
soda get TestCollection1 -k B58C675044F84408A8F058E71D1F38F1
Key: B58C675044F84408A8F058E71D1F38F1
Content: {
"employees": [
{ "employee_number": 7369, "employee_name": "SMITH", "department_number": 20 },
{ "employee_number": 7499, "employee_name": "ALLEN", "department_number": 30 }
]
}
-----------------------------------------
1 row selected.
SQL>
SQL>
soda get TestCollection1 -klist B58C675044F84408A8F058E71D1F38F1 45E8861FAF834353979DD74659B6E1E7
Key: 45E8861FAF834353979DD74659B6E1E7
Content: {"fruit": "apple"}
-----------------------------------------
Key: B58C675044F84408A8F058E71D1F38F1
Content: {
"employees": [
{ "employee_number": 7369, "employee_name": "SMITH", "department_number": 20 },
{ "employee_number": 7499, "employee_name": "ALLEN", "department_number": 30 }
]
}
-----------------------------------------
2 rows selected.
SQL>
SQL>
soda get TestCollection1 -f {"fruit": "apple"}
Key: 4D606ABF36C04E37BCDE088B30C4778D
Content: {"fruit": "apple"}
-----------------------------------------
1 row selected.
SQL>12345678910111213141516171819202122232425262728
SQL> soda get TestCollection1 -klist 45E8861FAF834353979DD74659B6E1E7
Key: 45E8861FAF834353979DD74659B6E1E7
Content: {"fruit": "apple"}
-----------------------------------------
1 row selected.
SQL>
SQL>
soda replace TestCollection1 45E8861FAF834353979DD74659B6E1E7 {"fruit": "banana"}
45E8861FAF834353979DD74659B6E1E7
Json String replaced successfully.
SQL>
SQL> soda get TestCollection1 -klist 45E8861FAF834353979DD74659B6E1E7
Key: 45E8861FAF834353979DD74659B6E1E7
Content: {"fruit": "banana"}
-----------------------------------------
1 row selected.
SQL>12345678910111213141516171819
SQL> soda count TestCollection1
2 rows selected.
SQL>
SQL>
soda remove TestCollection1 -k 45E8861FAF834353979DD74659B6E1E7
Successfully removed 1 record.
SQL>
SQL> soda count TestCollection1
1 row selected.
SQL>123456789101112131415
SQL> soda count TestCollection1
1 row selected.
SQL>
SQL> rollback;
Rollback complete.
SQL> soda count TestCollection1
No matching records found.
SQL>Please to add comments
No comments yet. Be the first to comment!