@@ -15,52 +15,29 @@ For more information about using JSON in Oracle Database see the
1515`Database JSON Developer’s Guide <https://www.oracle.com/pls/topic/
1616lookup?ctx=dblatest&id=ADJSN> `__.
1717
18- **Oracle Database 12c JSON Data Type **
19-
20- Prior to Oracle Database 21, JSON in relational tables is stored as
21- BLOB, CLOB or VARCHAR2 data, allowing easy access with node-oracledb.
22- All of these types can be used with node-oracledb in Thin or Thick mode.
23-
24- The older syntax to create a table with a JSON column is like:
25-
26- .. code-block :: sql
27-
28- CREATE TABLE j_purchaseorder (po_document BLOB CHECK (po_document IS JSON));
29-
30- The check constraint with the clause ``IS JSON `` ensures only JSON data
31- is stored in that column.
32-
33- The older syntax can still be used in Oracle Database 21, however the
34- recommendation is to move to the new JSON type. With the old syntax, the
35- storage can be BLOB, CLOB, or VARCHAR2. Of these, BLOB is preferred to
36- avoid character set conversion overheads.
18+ .. _json21ctype :
3719
38- **Oracle Database 21c JSON Data Type **
20+ Using the Oracle Database 21c JSON Type in node-oracledb
21+ ========================================================
3922
4023Oracle Database 21c introduced a dedicated JSON data type with a new
4124`binary storage format <https://blogs.oracle.com/database/post/
4225autonomous-json-database-under-the-covers-oson-format> `__
43- that improves performance and functionality. To use the new dedicated
44- JSON type, you can use node-oracledb 5.1 or later. The 21c JSON data
45- type can be used in both node-oracledb Thin and Thick modes. With Thick mode,
46- the Oracle Client libraries must be version 21, or later.
26+ that improves performance and functionality. To take advantage of the new
27+ dedicated JSON type in Oracle Database 21c and later versions, use
28+ node-oracledb 5.1 or later. For Thick mode, you must additionally use
29+ Oracle Client 21c ( or later) .
4730
48- In Oracle Database 21 or later, to create a table with a column called
31+ In Oracle Database 21c or later, to create a table with a column called
4932``PO_DOCUMENT `` for JSON data:
5033
5134.. code-block :: sql
5235
5336 CREATE TABLE j_purchaseorder (po_document JSON);
5437
55- .. _ json21ctype :
38+ ** Inserting JSON Data **
5639
57- Using the Oracle Database 21c JSON Type in node-oracledb
58- ========================================================
59-
60- Using node-oracledb Thin mode with Oracle Database 21c or later, or using
61- node-oracledb Thick mode or node-oracledb 5.1 (or later) with Oracle Database
62- 21c (or later) and Oracle Client 21c (or later), you can insert JavaScript
63- objects directly by binding as ``oracledb.DB_TYPE_JSON ``:
40+ To insert JavaScript objects directly by binding as ``oracledb.DB_TYPE_JSON ``:
6441
6542.. code-block :: javascript
6643
@@ -71,6 +48,10 @@ objects directly by binding as ``oracledb.DB_TYPE_JSON``:
7148 { bv: {val: data, type: oracledb .DB_TYPE_JSON } }
7249 );
7350
51+ .. _json21fetch :
52+
53+ **Fetching JSON Data **
54+
7455To query a JSON column, use:
7556
7657.. code-block :: javascript
@@ -86,11 +67,11 @@ The output is::
8667 }
8768 ]
8869
89- Using Oracle Client Libraries 19 or Earlier
90- -------------------------------------------
70+ Using Oracle Client Libraries 19c or Earlier
71+ --------------------------------------------
9172
92- If node-oracledb Thick mode uses Oracle Client Libraries 19 (or earlier),
93- querying an Oracle Database 21 (or later), then JSON column returns a
73+ If node-oracledb Thick mode uses Oracle Client Libraries 19c (or earlier),
74+ querying an Oracle Database 21c (or later), then JSON column returns a
9475:ref: `Lob Class <lobclass >` BLOB. You can stream the Lob or use
9576:meth: `lob.getData() `:
9677
@@ -117,6 +98,26 @@ shown above.
11798Using the Oracle Database 12c JSON Type in node-oracledb
11899========================================================
119100
101+ In Oracle Database versions 12c or later (prior to Oracle Database 21c), JSON
102+ in relational tables is stored as BLOB, CLOB, or VARCHAR2 data. All of these
103+ types can be used with node-oracledb in Thin or Thick mode.
104+
105+ The older syntax to create a table with a JSON column is like:
106+
107+ .. code-block :: sql
108+
109+ CREATE TABLE j_purchaseorder (po_document BLOB CHECK (po_document IS JSON));
110+
111+ The check constraint with the clause ``IS JSON `` ensures only JSON data
112+ is stored in that column.
113+
114+ The older syntax can still be used in Oracle Database 21c. However the
115+ recommendation is to move to the new JSON type. With the old syntax, the
116+ storage can be BLOB, CLOB, or VARCHAR2. Of these, BLOB is preferred to
117+ avoid character set conversion overheads.
118+
119+ **Inserting JSON Data **
120+
120121When using Oracle Database 12c or later with JSON using BLOB storage, you can
121122insert JSON strings:
122123
@@ -131,11 +132,27 @@ insert JSON strings:
131132 [b] // bind the JSON string
132133 );
133134
135+ **Fetching JSON Data **
136+
137+ With Oracle Database 12c (or later), you can fetch VARCHAR2 and LOB columns
138+ that contain JSON data in the same way that
139+ :ref: `JSON type columns <json21fetch >` are fetched when using Oracle
140+ Database 21c (or later). This can be done by setting
141+ :attr: `oracledb.future.oldJsonColumnAsObj ` to the value *true * as shown below.
142+ If you are using node-oracledb Thick mode, you must use Oracle Client 19c
143+ (or later) for this setting to work. For example:
144+
145+ .. code-block :: javascript
146+
147+ oracledb .future .oldJsonColumnAsObj = true ;
148+ const r = await conn .execute (` SELECT po_document FROM j_purchaseorder` );
149+ console .dir (r .rows , { depth: null });
150+
134151 IN Bind Type Mapping
135152====================
136153
137154When binding a JavaScript object as ``oracledb.DB_TYPE_JSON `` for
138- ``oracledb.BIND_IN `` or ``oracledb.BIND_INOUT `` in Oracle Database 21
155+ ``oracledb.BIND_IN `` or ``oracledb.BIND_INOUT `` in Oracle Database 21c
139156(or later), JavaScript values are converted to JSON attributes as shown
140157in the following table. The ‘SQL Equivalent’ syntax can be used in SQL
141158INSERT and UPDATE statements if specific attribute types are needed but
@@ -221,7 +238,7 @@ might be like::
221238Query and OUT Bind Type Mapping
222239===============================
223240
224- When getting Oracle Database 21 or later JSON values from the database, the
241+ When getting Oracle Database 21c or later JSON values from the database, the
225242following attribute mapping occurs:
226243
227244.. list-table-with-summary ::
0 commit comments