Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle update SQL Tips

Oracle Database Tips by Donald BurlesonMay 22, 2015

Question:  What is the syntax for an Oracle update statement?

Answer:  The Oracle update SQL syntax is too% ANSI compliant, and the Oracle documentation provides examples of the SQL update statement syntax. 

There are many o[options when updating Oracle, and you can update a Oracle table:

update emp set sal = sal *1.1 where . . . ;

The Oracle UPDATE statement locates one or more rows (or all the rows) in a table and sets one or more columns to the specified values. As with the INSERT statement, the values must either match the columns data type or one that the database can implicitly convert. The basic format is:

update <table name> set (<col1 = val1, col2 = val2,col3 = val3,?) where <expression identifying rows to change>;

Let's go back to the AUTHOR table and look at some examples of Oracle updates. As with the INSERT section, I rolled back the changes to the original table.

To set each author contract number to zero, simply leave off the WHERE clause. If you do not specify a row, then all rows are updated when Oracle update is used.

SQL> select author_key, author_contract_nbr from author;

AUTHOR_KEY AUTHOR_CONTRACT_NBR
----------- -------------------
A101 5601
A102 5602
A103 5603
A104 6602
A105 7896
A106 6547
A107 3452
A108 7954
A109 1
A110 2853

10 rows selected.

SQL> update author set author_contract_nbr = 0000;

10 rows updated.

The command returns the table to the state it was in before the Oracle updates.

To change the contract number for author A109 to 999, use the statement below. Notice that the WHERE clause identifies which row will be updated with Oracle UPDATE SQL.

SQL> update
2 author
3 set author_contract_nbr = 999
4 where
5 author_key = 'A109';

1 row updated.

I can also update multiple columns in one Oracle update. A comma separates each column to be updated. All of the columns identified will be changed for all the rows specified in the WHERE clause.

SQL> update
2 author
3 set author_contract_nbr = 8888,
4 author_zip = 32076
5 where
6 author_state = 'MO';

3 rows updated.

One of the powerful features of the Oracle update statement is the ability to update rows using a query.

update <table name> set (col1, col2, col3,?) = (<query>)
where <expression>;

The query must have a value in the select clause for each column in the column list. If the where clause is not used all rows are updated when the Oracle update is executed.

SQL> update
2 sales
3 set (order_date, quantity) = (select
4 SYSDATE,
5 avg(quantity)
6 from sales
7 where book_key = 'B102'
8 group by book_key, SYSDATE)
9 where book_key = 'B102';

11 rows updated.


Here are my other notes on Oracle update statement syntax and usage:

   
Oracle Training from Don Burleson 

The best on site "Oracle training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

Oracle training
 
 


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.