Skip to content

Commit 4986fa6

Browse files
Merge pull request #1820 from oracle-devrel/witold-swierzy-patch-4
Witold swierzy patch 4
2 parents b88efef + 4adbf34 commit 4986fa6

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Migration to JSON datatype
2+
3+
This area provides an example of migration of JSON data from pre-23ai model, which used LOB to store JSON data to JSON datatype, which has been implemented in Oracle Database 23ai.
4+
5+
# License
6+
7+
Copyright (c) 2025 Oracle and/or its affiliates.
8+
9+
Licensed under the Universal Permissive License (UPL), Version 1.0.
10+
11+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
drop table if exists JSONFLIGHTS_COL_LARGE;
2+
create json collection table JSONFLIGHTS_COL_LARGE;
3+
4+
begin
5+
dbms_cloud.copy_collection(collection_name => 'JSONFLIGHTS_COL_LARGE',
6+
credential_name => 'ajd_cred',
7+
file_uri_list => 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/fro8fl9kuqli/b/json_demo/o/flights-150m.json',
8+
format => json_object('recorddelimiter' value '''\n'''));
9+
end;
10+
/
11+
12+
drop table if exists jsonflights_col_19c;
13+
create table jsonflights_col_19c
14+
(id varchar2(32) primary key,
15+
data clob);
16+
17+
insert /*+parallel append */ into jsonflights_col_19c(id, data)
18+
select j.data."_id", j.data
19+
from jsonflights_col_large j
20+
where rownum <= 1000000;
21+
22+
commit;
23+
24+
alter table jsonflights_col_19c add (constraint ensure_json check(doc is json));
25+
26+
27+
28+
-- migration from clob to json datatype
29+
drop table if exists jsonflights_col_23ai;
30+
create json collection table jsonflights_col_23ai;
31+
32+
begin
33+
dbms_json.json_type_convertible_check(
34+
owner => 'ORADEV',
35+
tableName => 'JSONFLIGHTS_COL_19C',
36+
columnName => 'DATA',
37+
statusTableName => 'CHECK_TABLE');
38+
end;
39+
40+
select * from check_table;
41+
42+
insert /*+ parallel append */
43+
into jsonflights_col_23ai (data)
44+
select json(data)
45+
from jsonflights_col_19c;
46+
47+
commit;
48+
49+
begin
50+
dbms_stats.gather_table_stats('ORADEV','JSONFLIGHTS_COL_19C');
51+
dbms_stats.gather_table_stats('ORADEV','JSONFLIGHTS_COL_23AI');
52+
end;
53+
54+
select *
55+
from user_tables
56+
where table_name in ('JSONFLIGHTS_COL_19C','JSONFLIGHTS_COL_23AI');
57+
58+
59+
select json_serialize(data pretty) as data from jsonflights_col_23ai;
60+
61+
select json_serialize(data pretty) as data from jsonflights_col_19c;
62+
63+
select json_serialize(data pretty) as data from jsonflights_col_23ai j
64+
where j.data."DEP_DELAY" > 12
65+
66+
select json_serialize(data pretty) as data from jsonflights_col_19c j
67+
where j.data."DEP_DELAY" > 12

0 commit comments

Comments
 (0)