Oracle 10g 更新操作

來源:互聯網
上載者:User

1.單表更新

文法 :update test set column=value [,column=value]... [where condition]

eg :select * from test

eg: update test set sex=111 譯:整個表的sex列更新成111

eg: update test set sex=333 where AAA=7 譯:更新test表中某一個值

2.多表更新也叫使用子查詢更新

eg:將sal列的值更新為和emp表相同,如果使用常規的update語句,需要先將emp表SAL列的值查出,再使用update語句更新查詢後的結果值,這樣

做的話需要兩步操作,需要做額外的資料IO,而使用子查詢的話,可以有效地減少IO而提高執行效率。

update test set sal=(select sal from emp ) --錯誤提示單行子查詢返回多行

update test set sal=(select sal from emp where rownum=1) 譯:所有的sal列更新為一個值

update test set sal=(select sal from (select * from (select rownum r,sal from emp) where r=16 )) where AAA=8 譯:更新條件為AAA=8的sal的值

上面的更新語句分為三步

1.select * from (select rownum r,sal from emp) where r=16

2.select sal from (select * from (select rownum r,sal from emp) where r=16 )

3.賦值

select * from test where AAA=8

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.