Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support native JSON data type of Oracle Database 21c #1114

Closed
@PhilippSalvisberg

Description

@PhilippSalvisberg

Is your feature request related to a problem? Please describe

The Oracle Database 21c provides a native JSON data type in binary format. This data type can be used in tables, uses less space and is faster. See https://docs.oracle.com/en/database/oracle/oracle-database/21/adjsn/json-in-oracle-database.html#GUID-CBEDC779-39A3-43C9-AF38-861AE3FC0AEC

utPLSQL should support this data type similar as JSON_ELEMENT_T.

Currently the use of the native JSON data type leads to a runtime error.

Describe the solution you'd like

The following code

create table t (
   id     integer primary key,
   value  json
);

insert into t values (1, '{"a":"value a"}');
insert into t values (2, '{"a":"value a2"}');
commit;

declare
   l_actual sys_refcursor;
   l_expected sys_refcursor;
begin
   open l_actual for select value from t where id = 1;
   open l_expected for select value from t where id = 2;
   ut.expect(l_actual).to_equal(l_expected);
end;
/

should produce this result:

FAILURE
  Actual: json was expected to equal: json
  Diff: 1 differences found
  1 unequal values
    Actual value: "value a" was expected to be: "value a2" on path: $."a"

currently this code produces the following runtime error:

Error report -
ORA-01403: no data found
ORA-06512: at "UT3.UT_DATA_VALUE_REFCURSOR", line 113
ORA-06512: at "UT3.UT_COMPOUND_DATA_HELPER", line 620
ORA-06512: at "UT3.UT_CURSOR_DETAILS", line 111
ORA-06512: at "UT3.UT_DATA_VALUE_REFCURSOR", line 94
ORA-06512: at "UT3.UT_DATA_VALUE_REFCURSOR", line 22
ORA-06512: at "UT3.UT", line 83
ORA-06512: at line 7
01403. 00000 -  "no data found"
*Cause:    No data was found from the objects.
*Action:   There was no data from the objects which may be due to end of fetch.

Describe alternatives you've considered

As a workaround, you can manually convert the JSON data type to JSON_ELEMENT_T for the comparison.

Here's an example:

declare
   l_actual json_element_t;
   l_expected json_element_t;
   l_json json;
begin
   select value into l_json from t where id = 1;
   l_actual := json_element_t.parse(json_query(l_json, '$' returning clob));
   select value into l_json from t where id = 2;
   l_expected := json_element_t.parse(json_query(l_json, '$' returning clob));
   ut.expect(l_actual).to_equal(l_expected);
end;
/

As you see the code for JSON_ELEMENT_T could be reused to compare binary JSON data types. It should also possible to compare JSON_ELEMENT_T with a JSON.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions