% sql wksp_apexdev@localhost/freepdb1
SQLcl: 金 9月 05 19:02:19 2025のリリース25.2 Production
Copyright (c) 1982, 2025, Oracle. All rights reserved.
パスワード (**********?) ******
接続先:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.9.0.25.07
SQL>
create json collection table red_panda_lineage;
SQL> create json collection table red_panda_lineage;
JSON collection table RED_PANDA_LINEAGEは作成されました。
SQL>
以下のコードを実行し、JSONファイルを表RED_PANDA_LINEAGEに保存します。
SQL> declare
2 l_response clob;
3 e_get_json_failed exception;
4 begin
5 apex_web_service.set_request_headers('Content-Type','application/json');
6 l_response := apex_web_service.make_rest_request(
7 p_url => 'https://wwoast.github.io/redpanda-lineage/export/redpanda.json',
8 p_http_method => 'GET'
9 );
10 if apex_web_service.g_status_code <> 200 then
11 raise e_get_json_failed;
12 end if;
13 delete from red_panda_lineage;
14 insert into red_panda_lineage values(l_response);
15 commit;
16 end;
17* /
PL/SQLプロシージャが正常に完了しました。
SQL>
SQL> with vt as (
2 select json_dataguide(v.data, dbms_json.format_flat) as guide
3 from red_panda_lineage l, json_table(l.data, '$.vertices[*]'
4 columns data json path '$'
5 ) v
6 )
7 select jt.path, jt.type, jt.length
8 from vt,
9 json_table(vt.guide, '$'
10 columns (
11 nested path '$[*]'
12 columns (
13 path varchar2(4000) path '$."o:path"',
14 type varchar2(209) path '$.type',
15 length number path '$."o:length"'
16 )
17 )
18 ) jt
19 where jt.path not like '%photo%' and jt.path not like '%link%'
20* order by jt.path;
PATH TYPE LENGTH
____________________ _________ _________
$ object 1
$."cs.address" string 128
$."cs.location" string 32
$."cs.name" string 32
$."cs.othernames" string 64
$."da.address" string 64
$."da.location" string 64
$."da.name" string 32
$."de.address" string 64
$."de.location" string 32
$."de.name" string 64
$."de.othernames" string 32
$."en.address" string 128
$."en.location" string 64
$."en.name" string 64
$."en.nicknames" string 128
[中略]
$._id string 64
$.birthday string 16
$.closed string 16
$.commitdate string 16
$.death string 16
$.flag string 16
$.gender string 8
$.https string 64
$.latitude string 16
$.longitude string 16
$.map string 128
$.opened string 16
$.species string 1
$.uncertainty string 128
$.uncertainy string 64
$.uncertinty string 32
PATH TYPE LENGTH
____________ _________ _________
$.website string 128
124行が選択されました。
SQL>
SELECT文で検索される属性のうち、写真やリンクはWHERE句で対象から外しています。それ以外は、名前や住所が言語毎に属性になっています。今回は日本語と英語の情報だけを参照します。
SQL> with vt as (
2 select json_dataguide(v.data, dbms_json.format_flat) as guide
3 from red_panda_lineage l, json_table(l.data, '$.edges[*]'
4 columns data json path '$'
5 ) v
6 )
7 select jt.path, jt.type, jt.length
8 from vt,
9 json_table(vt.guide, '$'
10 columns (
11 nested path '$[*]'
12 columns (
13 path varchar2(4000) path '$."o:path"',
14 type varchar2(209) path '$.type',
15 length number path '$."o:length"'
16 )
17 )
18 ) jt
19* order by jt.path;
PATH TYPE LENGTH
________________ _________ _________
$ object 1
$._in string 32
$._label string 16
$._out string 4
$.probability string 4
SQL>
プロパティ・グラフの頂点を保存するマテリアライズド・ビューを、RED_PANDA_VERTICES_PANDAおよびRED_PANDA_VERTICES_ZOOとして作成します。idが0より大きい要素はレッサー・パンダで、idが0より小さい要素は動物園を表しています。
SQL> create or replace property graph red_panda_graph
2 vertex tables (
3 red_panda_vertices_panda key (panda_id)
4 label red_panda properties are all columns,
5 red_panda_vertices_zoo key (zoo_id)
6 label zoo properties are all columns
7 )
8 edge tables (
9 red_panda_edges_family key (id)
10 source key (vertex_in) references red_panda_vertices_panda (panda_id)
11 destination key (vertex_out) references red_panda_vertices_panda (panda_id)
12 label family
13 properties are all columns,
14 red_panda_edges_zoo key (id)
15 source key (vertex_in) references red_panda_vertices_panda (panda_id)
16 destination key (vertex_out) references red_panda_vertices_zoo (zoo_id)
17 label currentzoo
18 properties are all columns,
19 red_panda_edges_birthplace key (id)
20 source key (vertex_in) references red_panda_vertices_panda (panda_id)
21 destination key (vertex_out) references red_panda_vertices_zoo (zoo_id)
22 label birthplace
23 properties are all columns,
24 red_panda_edges_litter key (id)
25 source key (vertex_in) references red_panda_vertices_panda (panda_id)
26 destination key (vertex_out) references red_panda_vertices_panda (panda_id)
27 label litter
28 properties are all columns
29* );
Property GRAPHは作成されました。
SQL>