Oracle 10g update operation

Source: Internet
Author: User

1. Update a single table

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

Eg: select * from test

Eg: update test set sex = 111 Translation: update the sex column of the entire table to 111

Eg: update test set sex = 333 where AAA = 7: update a value in the test table

2. Multi-Table update is also called subquery update.

Eg: update the values of the sal column to the same value as the emp table. If you use a regular update statement, you must first check the values of the SAL column in the emp table, use the update statement to update the query result.

Two steps are required, and additional data I/O is required. Using subqueries can effectively reduce I/O and improve execution efficiency.

Update test set sal = (select sal from emp) -- the error message is "one row subquery returns multiple rows ".

Update test set sal = (select sal from emp where rownum = 1) Translation: All sal columns are updated to a value.

Update test set sal = (select sal from (select * from (select rownum r, sal from emp) where r = 16) where AAA = 8: update the sal value with the condition AAA = 8

The above update statement is divided into three steps

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. assign values

Select * from test where AAA = 8

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.