Site search

Categories

Archives

Tags

awr report delete syntax demobld demobld.sql determine oracle db size du find large file ftp script function syntax insert syntax kill oracle process linux du listener listener.log nfs mount instructions oracle constraint oracle database oracle database hosting oracle delete oracle demo build oracle demo setup oracle forein key constraint oracle ftp oracle functions oracle insert oracle process Oracle Scripts oracle select oracle subquery oracle update select syntax solaris sql background sql delete sql functions sql info sql insert sqlplus demo setup sql select sql update subquery syntax Technology Webcasts update syntax vnc tutorial vsftp
RSS
XML RSS
What is this?
AddThis Feed Button

Social
Bookmarking




-- FREE --
IT Magazine
Subscriptions

Oracle Magazine Oracle Magazine Contains technology strategy articles, sample code, tips, Oracle and partner news, how-to articles for developers and DBAs

WebSite Magazine WebSite Magazine Practical advice, helpful tools and insights for website owners

Dr Dobb's Journal Dr Dobb's Journal enables coders to write the most efficient programs and help in daily programming quandaries

DM Review DM Review is recognized as the premier business intelligence, analytics and data warehousing publication
Various other Free IT magazine subscriptions
NoAdware Free Trial

NoAdware Remove
harmful
adware,
spyware,
trojans,
dialers
and worms!
- Featured ebook -

Database Normalization
by Alf Pedersen

Database Normalization ebook Understand and master how to normalize a database using methods richly documented with graphical ERD and server diagram examples



Oracle Update syntax

The Oracle update statement allows you to change the data inside a table.

Syntax

update
set
= where ;

If you do not specify a where clause, all rows in the table will be updated.

Permissions
You must have update privileges to update another schema’s table.

If you want to update through a view, the view’s owner needs to have
update permissions on the base table and you need update privileges on the view.

The ‘update any table’ privilege sidesteps the 2 requirements above by combining them in one privilege.

Examples

Let’s use table SCOTT.DEPT as our example table.

DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

DEPT contains 3 columns (deptno, dname and loc) and 4 rows.

SQL> select * from dept;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

I want to update the location for department ‘SALES’ to ‘LONDON’.

SQL> update dept set loc = ‘LONDON’
where dname = ‘SALES’;

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from dept;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES LONDON
40 OPERATIONS BOSTON

Let’s update 2 columns at the same time:

SQL> update dept set loc = ‘MIAMI’, deptno = 50
where dname = ‘SALES’;

1 row updated.

SQL> select * from dept;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
50 SALES MIAMI
40 OPERATIONS BOSTON

SQL> commit;

Commit complete.

Let’s use a function to change the value of the location column:

SQL> update dept set loc = lower(loc) ;

4 rows updated.

SQL> commit;

Commit complete.

SQL> select * from dept;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING new york
20 RESEARCH dallas
50 SALES miami
40 OPERATIONS boston

Lastly: do not forget to commit to make your changes permanent.

Recommended reading:

# Oracle Online Documentation: SQL Reference, Update statement