Oracle更新資料的方法

2021-08-11 14:59:51 字數 1012 閱讀 9451

1.普通更新update

當你需要更新的表是單個或者被更新的字段不需要關聯其他錶帶過來,則最後選擇標準的

update

語句,速度最快,穩定性最好,並返回影響條數。如果

where

條件中的字段加上索引,那麼更新效率就更高。

但對需要關聯表更新欄位時,

update

的效率就非常差。

2.inline view

更新法

inline view

更新法就是更新乙個臨時建立的檢視。

update (select a.blzt as blzt,b.ft_lstate as ft_lstate

from gkfq_rec a,oa2_ftask b where a.slid=b.fi_inst) 

set blzt=ft_lstate;

3.merge into 更新法

merge into 表名 alias 1

using (table|view|sub_query) alias 2

on (join condition兩個表的關聯條件)

when matched then

update 

set alias1.col=alias2.col

when not matched then

insert (column_list) values (column_values);

方法描述

適用範圍

執行效率

傳統方案

一般情況適用

單錶更新效率高且穩定,多表時效率較慢

inline view更新法

關聯字段為主鍵

速度較快

merge更新法

關聯欄位非主鍵,適用於兩表關聯

非主鍵關聯表更新,速度較快

快速游標更新法

邏輯較複雜的情況

複雜邏輯時效率很高

oracle批量更新資料

目的 兩個表t1,t2,t1裡面的字段,id,name,t2也是,將t2表和t1表裡面相等的id的記錄的name欄位更新到t1表裡面 1 update t1 set name select t2.name from t2 where t2.id t1.id where exits select 1 ...

oracle 資料更新講解

1 更新乙個列 update t person set age 30 2 更新多個列 update t person set age 30,name tom 3 更新一部分資料 update t person set age 30 where name tom 用where語句表示只更新name是 ...

ORACLE 資料插入或者更新

在寫入資料的時候有時候需要根據資料庫中是否含有該條資料來判斷資料是插入還是更新,以下為oracle插入更新語法 單條資料錄入 select sys seq.nextval as id from dual merge into sys token a using select as id,as use...