<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oracle Database Tips blog &#187; update syntax</title>
	<atom:link href="http://oracle-database-tips.com/wp/tag/update-syntax/feed" rel="self" type="application/rss+xml" />
	<link>http://oracle-database-tips.com/wp</link>
	<description>News for Oracle professionals</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:37:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Oracle Update syntax</title>
		<link>http://oracle-database-tips.com/wp/sql/oracle-update-syntax</link>
		<comments>http://oracle-database-tips.com/wp/sql/oracle-update-syntax#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:02:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[location column]]></category>
		<category><![CDATA[oracle update]]></category>
		<category><![CDATA[privileges]]></category>
		<category><![CDATA[sql update]]></category>
		<category><![CDATA[table syntax]]></category>
		<category><![CDATA[update syntax]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=70</guid>
		<description><![CDATA[Look at these examples of the Oracle SQL Update statement]]></description>
			<content:encoded><![CDATA[<p>The Oracle update statement allows you to change the data inside a table.</p>
<p>Syntax</p>
<p>update<br />
<table_name> set<br />
<column list> = <value list> where <restriction clause>;</p>
<p>If you do not specify a where clause, all rows in the table will be updated.</p>
<p>Permissions<br />
You must have update privileges to update another schema&#8217;s table.</p>
<p>If you want to update through a view, the view&#8217;s owner needs to have<br />
update permissions on the base table and you need update privileges on the view.</p>
<p>The &#8216;update any table&#8217; privilege sidesteps the 2 requirements above by combining them in one privilege.</p>
<p>Examples</p>
<p>Let&#8217;s use table SCOTT.DEPT as our example table.</p>
<p>DEPTNO 	DNAME 	LOC<br />
10 	ACCOUNTING 	NEW YORK<br />
20 	RESEARCH 	DALLAS<br />
30 	SALES 	CHICAGO<br />
40 	OPERATIONS 	BOSTON</p>
<p>DEPT contains 3 columns (deptno, dname and loc) and 4 rows.</p>
<p>SQL> select * from dept;</p>
<p>    DEPTNO DNAME          LOC<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;-<br />
        10 ACCOUNTING     NEW YORK<br />
        20 RESEARCH       DALLAS<br />
        30 SALES          CHICAGO<br />
        40 OPERATIONS     BOSTON</p>
<p>I want to update the location for department &#8216;SALES&#8217; to &#8216;LONDON&#8217;.</p>
<p>SQL> update dept set loc = &#8216;LONDON&#8217;<br />
     where dname = &#8216;SALES&#8217;;</p>
<p>1 row updated.</p>
<p>SQL> commit;</p>
<p>Commit complete.</p>
<p>SQL> select * from dept;</p>
<p>    DEPTNO DNAME          LOC<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;-<br />
        10 ACCOUNTING     NEW YORK<br />
        20 RESEARCH       DALLAS<br />
        30 SALES          LONDON<br />
        40 OPERATIONS     BOSTON</p>
<p>Let&#8217;s update 2 columns at the same time:</p>
<p>SQL> update dept set loc = &#8216;MIAMI&#8217;, deptno = 50<br />
     where dname = &#8216;SALES&#8217;;</p>
<p>1 row updated.</p>
<p>SQL> select * from dept;</p>
<p>    DEPTNO DNAME          LOC<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;-<br />
        10 ACCOUNTING     NEW YORK<br />
        20 RESEARCH       DALLAS<br />
        50 SALES          MIAMI<br />
        40 OPERATIONS     BOSTON</p>
<p>SQL> commit;</p>
<p>Commit complete.</p>
<p>Let&#8217;s use a function to change the value of the location column:</p>
<p>SQL> update dept set loc = lower(loc) ;</p>
<p>4 rows updated.</p>
<p>SQL> commit;</p>
<p>Commit complete.</p>
<p>SQL> select * from dept;</p>
<p>    DEPTNO DNAME          LOC<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;-<br />
        10 ACCOUNTING     new york<br />
        20 RESEARCH       dallas<br />
        50 SALES          miami<br />
        40 OPERATIONS     boston</p>
<p>Lastly: do not forget to commit to make your changes permanent.</p>
<p>Recommended reading:</p>
<p># Oracle Online Documentation: SQL Reference, Update statement</p>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/oracle-update-syntax/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

