この例では、1つのJSON_SHRED_BATCH呼び出しを使用して2つのテーブルにデータを入力します。
この例を実行する前に、ソース テーブル(json_table)に対してSELECT権限があること、およびターゲット テーブル(emp_table、dept_table)に対してINSERT権限があることを確認します。
CALL SYSLIB.JSON_SHRED_BATCH(
'SELECT id, empPersonalInfo, site FROM test.json_table',
'[
{
"rowexpr" : "$.employees.info[*]",
"colexpr" : [
{"col1" : "$.id",
"type" : "INTEGER"},
{"col2" : "$.employees.company",
"type" : "VARCHAR(15)",
"fromRoot" : true},
{"col3" : "$.name",
"type" : "VARCHAR(20)"},
{"col4" : "$.age",
"type" : "INTEGER"},
{"col5" : "$.dept",
"type" : "VARCHAR(20)"}
],
"queryexpr" : [
{"site" : "VARCHAR(20)"}
],
"tables" : [
{
"test.emp_table" : {
"metadata" : { "operation" : "insert" },
"columns" : {
"empID" : "col1*100",
"company" : "col2",
"empName" : "col3",
"empAge" : "col4",
"dept" : "col5",
"startDate" : "CURRENT_DATE",
"site" : "site" }
}
},
{
"test.dept_table" : {
"metadata" : { "operation" : "insert" },
"columns" : {
"dept" : "col5",
"description" : ["CONSTANT DESCRIPTION"],
"empID" : "col1"
}
}
}
]
}
]', :res );
上記のシュレッドの結果、emp_tableテーブルとdept_tableテーブルに3つの行が挿入され、ソース データとして使用するJSONオブジェクトの3つの項目に対応します。
結果: employeeテーブルに挿入されたデータを表示するには次を実行します。SELECT * FROM emp_table ORDER BY empID;
empID company empName empAge dept startDate site ----- ------------ --------- ------ ------------ ---------- ----- 100 Teradata Cameron 24 engineering 15/02/10 RB 200 Teradata Justin 30 engineering 15/02/07 RB 300 Teradata Melissa 24 marketing ? RB
結果: departmentテーブルに挿入されたデータを表示するには次を実行します。SELECT * FROM dept_table ORDER BY dept, empID;
dept description empID -------------------------------------- engineering CONSTANT DESCRIPTION 1 engineering CONSTANT DESCRIPTION 2 marketing CONSTANT DESCRIPTION 3