I was testing transaction backout with non-scalar datatypes. And since I’m doing JSON research I decided to try JSON columns. I discovered that transaction backout does not work with JSON. Not sure just why yet. Here is the test code I used.
SQL> CREATE TABLE JSON
2 ( always_json CLOB
3 CONSTRAINT keep_it_real
4* CHECK ( always_json IS JSON ) )
SQL> INSERT INTO json
5 "plch_id" : "1",
6 "plch_desc" : "One"
1 row created.
SQL> CREATE OR REPLACE PACKAGE hold_stuff AS
2 v_scn NUMBER;
2 hold_stuff.v_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER;
PL/SQL procedure successfully completed.
SQL> SET TRANSACTION NAME 'DELETE';
SQL> DELETE json;
1 row deleted.
2 v_names SYS.TXNAME_ARRAY := SYS.TXNAME_ARRAY('DELETE');
4 DBMS_FLASHBACK.TRANSACTION_BACKOUT( numtxns => 1,
5 names => v_names,
6 scnhint => hold_stuff.v_scn );
ERROR at line 1:
ORA-55511: Flashback Transaction experienced error in executing undo SQL
ORA-02290: check constraint (ORA-02290: check constraint (DRH.KEEP_IT_REAL)
ORA-06512: at "SYS.DBMS_FLASHBACK", line 51
ORA-06512: at "SYS.DBMS_FLASHBACK", line 86
ORA-06512: at line 4
I'm unable to see what Oracle used for the undo operation (an INSERT) but it will be interesting once I find it.
Thanks for reading!
As a long tine use of Relational Databases I live by the rule that data must be stored in and retrieved from table. And those tables must have columns. But JSON plays by it’s own rules by allowing random attribute-value pairs with no consistency enforced. But the latest version of my most used database, Oracle offers a way to store and retrieve this data in a JSON column in a table; and to retrieve it with a JSON_TABLE function. Here is an example:
-- create a table with a single JSON column
SQL> CREATE TABLE its_json_thanks
2 ( json_only_please CLOB,
3 CONSTRAINT json_only
4 CHECK ( json_only_please IS JSON ) );
-- Insert some valid JSON
SQL> INSERT INTO its_json_thanks
5 "primary_key" : "1",
6 "unique_key" : "1"
1 row created.
-- Query the values out
SQL> SELECT pk,
3 FROM its_json_thanks ijt,
5 COLUMNS( pk VARCHAR2(10) PATH '$.primary_key',
6 uk VARCHAr2(10) PATH '$.unique_key' ))
7 WHERE ijt.json_only_please.primary_key = '1'
1 row selected
The JSON_TABLE function performs a self-join between the table and the JSON column it contains. It also aligns the attributes (primary key and unique key) with column names (PK and UK).
Oracle quite adept at serving non-tabular data (XML,etc) up in a columnar format for applications that need to see it that way while allowing other applications to interact in their native format.
I’d explain the JSON_TABLE example as a conversation between a maitre’d and a customer like this:
MD: Welcome, Primary JSON. How many in your party?
MRJ: Two please. Me and my wife, Unique.
MD: Ah yes, the famous PK and UK. We have a one dollar,
two seater near the window for you.
Or maybe not.
Thanks for reading.