使用資料庫操作 (SQL Developer Web),單擊“新建 JSON 檔案”按鈕將新的 JSON 檔案添加到集合中非常容易。
集合當然是Oracle中的一個表,表本身有很多列:

我已經使用 PL/SQL 處理程式在 ORDS 中創建了模塊。雖然我可以在這里使用更新 JSON 檔案
UPDATE "Collection" SET json_document = '{"key": "value"}' WHERE JSON_VALUE(json_document, '$.id') = :id'
我無法輕松添加新檔案
INSERT INTO "Collection" (json_document) VALUES ('{"key": "value"}')
因為id被設定為 PK 列并且必須指定。我如何使用 PL/SQL 在別處添加帶有自動生成欄位的新檔案?或者我應該使用 SODA for PL/SQL 來實作這一點?
謝謝!
uj5u.com熱心網友回復:
您可以使用該dbms_soda包訪問該集合。然后使用方法soda_colletion_t來操作它。
例如:
soda create students;
declare
collection soda_collection_t;
document soda_document_t;
status number;
begin
-- open the collection
collection := dbms_soda.open_collection('students');
document := soda_document_t(
b_content => utl_raw.cast_to_raw (
'{"id":1,"name":"John Blaha","class":"1980","courses":["c1","c2"]}'
)
);
-- insert a document
status := collection.insert_one(document);
end;
/
select * from students;
ID CREATED_ON LAST_MODIFIED VERSION JSON_DOCUMENT
-------------------------------- ------------------------ ------------------------ -------------------------------- ---------------
A92F68753B384F87BF12557AC38098CB 2021-12-22T14:15:12.831Z 2021-12-22T14:15:12.831Z FE8C80FED46A4F18BFA070EF46073F43 [object Object]
有關如何將 SODA 用于 PL/SQL 的完整檔案和示例,請參見此處。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/391957.html
