update多列更新

2021-08-26 19:33:01 字數 732 閱讀 4967

再etl的時候,經常會遇到列轉換的問題,再對照轉換中出現多列更新的時候,一下是我總結的一些:

當update多列時有如下幾種選擇

1.)教科書式寫法

update t_table a

set f1=(select f1 from testz b where a.id=b.id),

f2=(select f2 from testz b where a.id=b.id),

f3=(select f3 from testz b where a.id=b.id)

where id=2;

2.)教科書變種

update t_table a

set (f1,f2,f3)=(select f1,f2,f3 from testz b where a.id=b.id)

where id=2;

雖然道理和方法1一樣,卻省了不少事

3.)另類nest table寫法

update (select f1,f2,f3 from t_table where id=2)

set (f1,f2,f3)=(select f1,f2,f3 from testz b where id=2);

此方法雖然比2的**量要多一些,但是沒有表連線,如果兩個表都在id列有主鍵,速度應該較方法1和方法2快一些.

說明:update是乙個耗回滾段,耗重做日誌,耗時間,耗成本的操作,尤其是大表的多列update,如有必要應比較其與重新建表的效率.

update多列的幾種選擇

當 update 多列 時有如下幾種選擇 1.教科書式寫法 update t table a set f1 select f1 from testz b where a.id b.id f2 select f2 from testz b where a.id b.id f3 select f3 fr...

update 更新語句

update 語句用於修改表中的資料。update 表名稱 set 列名稱 新值 where 列名稱 某值 lastname firstname address city gates bill xuanwumen 10 beijing wilson champs elysees 我們為 lastna...

update 語句更新順序

create table tb 產品 varchar 2 數量 int,日期 varchar 4 單據號 varchar 4 insert into tb select a 10,9.1 001 union all select a 3,9.2 002 union all select a 4,9....