Byzer Oracle Upsert 功能介紹

功能介紹

新發(fā)布的 Byzer 2.2.2 提供了 Oracle Upsert 功能。Upsert 意思是當(dāng)數(shù)據(jù)庫(kù)表存在數(shù)據(jù)時(shí) Insert , 否則 Update。舉個(gè)例子,有表 table_1

c1 c2
1 "a"

Upsert 的 結(jié)果集為

c1 c2
1 "a_updated"
2 "b"

Upsert時(shí),table_1 不包含 c1=2 的數(shù)據(jù),Insert ; 包含 c1=1 的數(shù)據(jù),則 Update.

使用方式

我們以 Linux 為例說(shuō)明。

  1. 下載 Byzer-lang 2.2.2 & Byzer-notebook 1.1.1, 參考 Byzer-lang 安裝文檔 Byzer-notebook 安裝文檔

  2. 下載 Oracle JDBC 包,請(qǐng)根據(jù) Oracle 版本選擇適配的 JDBC 版本。并拷貝至 Byzer-lang 安裝目錄的 libs 子目錄。

  3. 執(zhí)行 Byzer-lang 安裝目錄 bin/start-local.sh 以啟動(dòng) Byzer-lang .

  4. 檢查 byzer-notebook 安裝目錄 conf/notebook.propertiesnotebook.mlsql.engine-url 是否指向 byzer-lang; 并確保 conf/notebook.properties 配置的 MySQL 能聯(lián)通。啟動(dòng) Byzer-notebook。

  5. 瀏覽器 打開(kāi) http://<byzer-notebook-ip>:9002conf/notebook.properties 配置項(xiàng)notebook.port=9002。

  6. 第一次登錄時(shí),填寫(xiě)用戶名密碼,再點(diǎn)擊注冊(cè)。再次登錄即可。

  7. 新建一個(gè) Notebook,開(kāi)始寫(xiě)代碼。


CONNECT jdbc WHERE
 url="jdbc:oracle:thin:<username>/<password>@<oracle_host>:<port>/orclpdb1.localdomain"
 and driver="oracle.jdbc.driver.OracleDriver"
 AS db_1;

SELECT 1 c1 ,"1_update" c2
UNION ALL
SELECT 2 c1, "2" c2  AS records;
 
SAVE APPEND records as jdbc.`db_1.zjc_11` WHERE idCol="c1";

APPEND 表明 Upsert Oracle;且 idCol = "c1" 表明 Upsert 時(shí) 比較 zjc_11c1 字段。

如果你碰到問(wèn)題,歡迎加入 slack 提問(wèn)。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容