|
| 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