exampleJsonTableに対する問合せの例
Oracle Big Data SQLを使用してOracle NoSQL Database exampleJsonTable
内のデータを問い合せるには、Oracle NoSQL Databaseストア内のその表にマップしたOracle Database外部表に対して、次のような問合せを実行します。次に例を示します。
set linesize 500;
col id format 9999;
col jsonfield format A1000;
SELECT * FROM exampleJsonTable WHERE ROWNUM <= 5;
次の問合せでは、JSONドット表記法、JSON_VALUE
演算子およびJSON_QUERY
演算子の様々な組合せを使用して、Oracle NoSQL Database表の各行のJSONドキュメントの特定の属性のみを問い合せて表示します。
JSONドット表記法のみを使用した問合せ
col personal format A15;
col party format A15;
SELECT id, j.jsonfield.personal.firstname,
j.jsonfield.personal.lastname, j.jsonfield.party
FROM exampleJsonTable j
WHERE j.jsonfield.party = 'Independent'
ORDER BY j.jsonfield.person.lastname;
JSONドット表記法およびJSON_VALUE演算子を使用した問合せ
col firstname format A15;
col lastname format A15;
col homephone format A12;
col workphone format A12;
SELECT id,
JSON_VALUE(j.jsonfield, '$.personal.firstname') firstname,
JSON_VALUE(j.jsonfield, '$.personal.lastname') lastname,
JSON_VALUE(j.jsonfield, '$.personal.party') party,
JSON_VALUE(j.jsonfield, '$.personal.address.home.phone') homephone,
JSON_VALUE(j.jsonfield, '$.personal.address.work.phone') workphone
FROM exampleJsonTable j
ORDER BY j.jsonfield.party;
JSONドット表記法およびJSON_QUERY演算子を使用した問合せ
col committee format A25;
col caucus format A25;
SELECT id, j.jsonfield.personal.firstname,
j.jsonfield.personal.lastname,
JSON_QUERY(j.jsonfield, '$.duties.committee' PRETTY WITH WRAPPER) committee,
JSON_QUERY(j.jsonfield, '$.duties.caucus' PRETTY WITH WRAPPER) caucus
FROM exampleJsonTable j
WHERE j.jsonfield.party = 'Democrat' AND ROWNUM <= 5;
JSONドット表記法およびJSON_VALUEとJSON_QUERYの両方を使用した問合せ
col contrib format A12;
col committee format A50;
col contrib format A50;
SELECT
JSON_VALUE(j.jsonfield, '$.personal.firstname') firstname,
JSON_VALUE(j.jsonfield, '$.personal.lastname') lastname,
j.jsonfield.contrib,
j.jsonfield.party,
JSON_QUERY(j.jsonfield, '$.duties.committee' PRETTY WITH WRAPPER) committee,
JSON_QUERY(j.jsonfield, '$.duties.caucus' PRETTY WITH WRAPPER) caucus
FROM exampleJsonTable j
WHERE j.jsonfield.party = 'Republican' AND ROWNUM <= 5;