<?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; SQL</title>
	<atom:link href="http://oracle-database-tips.com/wp/category/sql/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>Finding out which spid is related to a dbms_job.</title>
		<link>http://oracle-database-tips.com/wp/sql/finding-out-which-spid-is-related-to-a-dbms_job</link>
		<comments>http://oracle-database-tips.com/wp/sql/finding-out-which-spid-is-related-to-a-dbms_job#comments</comments>
		<pubDate>Fri, 10 Jun 2011 12:26:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[culprit]]></category>
		<category><![CDATA[dbms_job]]></category>
		<category><![CDATA[dj job]]></category>
		<category><![CDATA[djr]]></category>
		<category><![CDATA[ef]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[head job]]></category>
		<category><![CDATA[interval]]></category>
		<category><![CDATA[last date]]></category>
		<category><![CDATA[os level]]></category>
		<category><![CDATA[process id]]></category>
		<category><![CDATA[session id]]></category>
		<category><![CDATA[spid]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=149</guid>
		<description><![CDATA[This is useful when you find that a runaway ghost process is hogging CPU or memory and you can see what the OS level sid is, but you have no idea which job it is related to]]></description>
			<content:encoded><![CDATA[<p>Found a handy post about finding out the spid of a running job.</p>
<p>This is useful when you find that a runaway ghost process is hogging CPU or memory and you can see what the OS level sid is, but you have no idea which job it is related to:</p>
<p>For example, running top showed you that process 25042 is a problem and ps -ef | grep 25042 shows you that it is Oracle process  ora_j001_&lt;sid&gt;.</p>
<p>Well, run the following query and you will see which job is the culprit:</p>
<p>set linesize 250<br />
col sid for 9999 head &#8216;Session|ID&#8217;<br />
col spid head &#8216;O/S|Process|ID&#8217;<br />
col serial# for 9999999 head &#8216;Session|Serial#&#8217;<br />
col log_user for a10<br />
col job for 9999999 head &#8216;Job&#8217;<br />
col broken for a1 head &#8216;B&#8217;<br />
col failures for 99 head &#8220;fail&#8221;<br />
col last_date for a18 head &#8216;Last|Date&#8217;<br />
col this_date for a18 head &#8216;This|Date&#8217;<br />
col next_date for a18 head &#8216;Next|Date&#8217;<br />
col interval for 9999.000 head &#8216;Run|Interval&#8217;<br />
col what for a60<br />
select j.sid,<br />
s.spid,<br />
s.serial#,<br />
j.log_user,<br />
j.job,<br />
j.broken,<br />
j.failures,<br />
j.last_date||&#8217;:'||j.last_sec last_date,<br />
j.this_date||&#8217;:'||j.this_sec this_date,<br />
j.next_date||&#8217;:'||j.next_sec next_date,<br />
j.next_date &#8211; j.last_date interval,<br />
j.what<br />
from (select djr.SID,<br />
dj.LOG_USER, dj.JOB, dj.BROKEN, dj.FAILURES,<br />
dj.LAST_DATE, dj.LAST_SEC, dj.THIS_DATE, dj.THIS_SEC,<br />
dj.NEXT_DATE, dj.NEXT_SEC, dj.INTERVAL, dj.WHAT<br />
from dba_jobs dj, dba_jobs_running djr<br />
where dj.job = djr.job ) j,<br />
(select p.spid, s.sid, s.serial#<br />
from v$process p, v$session s<br />
where p.addr = s.paddr ) s<br />
where j.sid = s.sid;</p>
<p>The rest of the post discusses how to kill the ghost process as well as the job, read it <a href="http://it.toolbox.com/blogs/database-solutions/killing-the-oracle-dbms_job-6498" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/finding-out-which-spid-is-related-to-a-dbms_job/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Foreign key constraints and other type of constraints in an Oracle database</title>
		<link>http://oracle-database-tips.com/wp/sql/foreign-key-constraints-and-other-type-of-constraints-in-an-oracle-database</link>
		<comments>http://oracle-database-tips.com/wp/sql/foreign-key-constraints-and-other-type-of-constraints-in-an-oracle-database#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:16:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[amp]]></category>
		<category><![CDATA[check constraint]]></category>
		<category><![CDATA[check constraints]]></category>
		<category><![CDATA[empl]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[jones 1]]></category>
		<category><![CDATA[lower case]]></category>
		<category><![CDATA[null value]]></category>
		<category><![CDATA[oracle constraint]]></category>
		<category><![CDATA[oracle constraints]]></category>
		<category><![CDATA[oracle forein key constraint]]></category>
		<category><![CDATA[surname table]]></category>
		<category><![CDATA[uniqueness]]></category>
		<category><![CDATA[upper case]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=79</guid>
		<description><![CDATA[A foreign key is one of the different types of Oracle constraints.]]></description>
			<content:encoded><![CDATA[<p>A foreign key is one of the different types of Oracle constraints.<br />
The purpose of a constraint is literally to constrain or restrict the quality of          data which you are allowed to insert into a table.</p>
<p>There are 5 kinds of constraints :</p>
<ul class="medium">
<li><a href="#CK">Check</a></li>
<li><a href=#NK">Not-Null</a></li>
<li><a href="#UK">Unique</a></li>
<li><a href="#PK">Primary Key</a></li>
<li><a href="l#FK">Foreign Key</a></li>
</ul>
<h3><a id="CK" name="CK"></a><br />
Check Constraints</h3>
<p>A check constraint allows you to define a function which determines whether          the data is allowable or not.</p>
<p>Example: Let&#8217;s add a check constraint to employees.surname  (table Employees, column Surname)<br />
which will only allow characters to be entered in upper case:</p>
<div id="textbox">
<div>SQL&gt; alter table employees add constraint ch_employees check (surname = upper(surname));</div>
</div>
<p>If you try to add a surname in lower case , you will receive the following        error:</p>
<div id="textbox">
<div>SQL&amp;gtinsert into employees (surname) values (&#8216;jones&#8217;)</p>
<p>ORA-02290: check constraint (CH_EMPLOYEES) violated</p></div>
</div>
<p>Now let&#8217;s add it the proper way:</p>
<div id="textbox">
<div>SQL&gt; insert into employees (surname) values (&#8216;JONES&#8217;);</p>
<p>1 row created.</p></div>
</div>
<h3><a id="NK" name="NK"></a><br />
Not-Null Constraints</h3>
<p>This simple constraint determines whether your column is allowed to contain    null data.<br />
By default, a column can contain null data, unless you add a not-null constraint.</p>
<p>Example :  Let&#8217;s add a not-null constraint to Employees.Surname</p>
<div id="textbox">
<div>SQL&gt;alter table employees modify (surname not null);</div>
</div>
<p>Now try to insert a null value.</p>
<div id="textbox">
<div>SQL&gt; insert into employees (surname) values (null);</p>
<p>ORA-01400: cannot insert NULL into (&#8220;EMPLOYEES&#8221;.&#8221;SURNAME&#8221;)</p></div>
</div>
<h3><a id="UK" name="UK"></a><br />
Unique Constraints</h3>
<p>These constraints enforce uniqueness in your column&#8217;s data : it will stop duplicated    data from being inserted.</p>
<p>Example:</p>
<div id="textbox">
<div>SQL&gt; alter table employees add constraint u_employees unique enable validate;</div>
</div>
<p>We know there is already an entry named &#8216;JONES&#8217; in the table, so let&#8217;s see    what happens when we try to insert it again:</p>
<div id="textbox">
<div>SQL&gt; insert into employees (surname) values (&#8216;JONES&#8217;);</p>
<p>ORA-00001: unique constraint (U_EMPLOYEES) violated</p></div>
</div>
<h3><a id="PK" name="PK"></a><br />
Primary Key Constraints</h3>
<p>A primary key constraint is a combination of a unique <em>and</em> a not-null constraint.<br />
It allows you to use a column in your table to uniquely identify each row by your predetermined key.<br />
Creating a primary key automatically creates a unique index of the same name on the table.<br />
This is how Oracle enforces the uniqueness.</p>
<p>Example: Before we can create a primary key, let&#8217;s drop the previous not-null and unique key constraints.</p>
<div id="textbox">
<div>SQL&gt; alter table employees modify(surname  null);</p>
<p>SQL&gt; alter table employees  drop constraint u_employees;</p>
<p>SQL&gt; alter table employees add constraint pk_employee primary key (surname);</p></div>
</div>
<p>Either inserting a pre-existing surname or attempting to insert a null value into the surname column<br />
will now result in an error.</p>
<div id="textbox">
<div>SQL&gt; insert into employees (surname) values (&#8216;JONES&#8217;);</p>
<p>ORA-00001: unique constraint (PK_EMPLOYEES) violated</p>
<p>SQL&gt; insert into employees (surname) values (null);</p>
<p>ORA-01400: cannot insert NULL into (&#8220;EMPLOYEES&#8221;.&#8221;SURNAME&#8221;)</p></div>
</div>
<h3><a id="FK" name="FK"></a><br />
Foreign Key Constraints</h3>
<p>Another name for these is relational integrity constraints.<br />
They enforce logical relationships between parent and child tables.</p>
<p>Let&#8217;s use a geographical example.</p>
<p>We have a parent table called Countries and a child table called Cities.<br />
A row in the Cities table must be able to find its parent Country in the Countries table<br />
before you are allowed to  insert the City.</p>
<p>Parent table <em>Countries</em> :</p>
<table border="1" cellspacing="0" cellpadding="0" width="203">
<tbody>
<tr>
<td width="64">CountryID</td>
<td width="133">CountryName</td>
</tr>
<tr>
<td>1</td>
<td>UK</td>
</tr>
<tr>
<td>2</td>
<td>USA</td>
</tr>
<tr>
<td>3</td>
<td>INDIA</td>
</tr>
</tbody>
</table>
<p>Child table <em>Cities</em>:</p>
<table border="1" cellspacing="0" cellpadding="0" width="294">
<tbody>
<tr>
<td width="80">CityID</td>
<td width="108">CityName</td>
<td width="98">CountryID</td>
</tr>
<tr>
<td>M00001</td>
<td>MADRAS</td>
<td>3</td>
</tr>
<tr>
<td>F00001</td>
<td>FARMINGTON</td>
<td>2</td>
</tr>
<tr>
<td>B00001</td>
<td>BOISE</td>
<td>2</td>
</tr>
<tr>
<td>L00001</td>
<td>LONDON</td>
<td>1</td>
</tr>
<tr>
<td>B00002</td>
<td>BANGALORE</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>To implement this is slightly more complicated than the other constraints:<br />
First you create the primary key on the parent table:</p>
<div id="textbox">
<div>SQL&gt; alter table countries add constraint pk_countries  primary key (countryid);</div>
</div>
<p>Now we create the foreign key constraint on the child table which references the primary key on the parent table:</p>
<div id="textbox">
<div>SQL&gt; alter table cities add constraint fk_cities foreign key (countryid) references countries (countryid);</div>
</div>
<p>Time to test:  let&#8217;s try to add a row in Cities with a non-existent Countryid.</p>
<div id="textbox">
<div>SQL&gt; insert into cities (cityid, cityname, countryid) values (&#8216;M00002&#8242;,&#8217;MELBOURNE&#8217;,5);</p>
<p>ORA-02291: integrity constraint (FK_CITIES) violated &#8211; parent key not found</p></div>
</div>
<h3>Recommended reading:</h3>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14220%2Fintro.htm%23sthref227&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fforeign_key.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref227" target="_blank">Oracle online documentation: Database Concepts</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/foreign-key-constraints-and-other-type-of-constraints-in-an-oracle-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Functions</title>
		<link>http://oracle-database-tips.com/wp/sql/oracle-functions</link>
		<comments>http://oracle-database-tips.com/wp/sql/oracle-functions#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:13:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[ceil]]></category>
		<category><![CDATA[chr]]></category>
		<category><![CDATA[function syntax]]></category>
		<category><![CDATA[handy utilities]]></category>
		<category><![CDATA[oracle functions]]></category>
		<category><![CDATA[oracle top]]></category>
		<category><![CDATA[rtrim]]></category>
		<category><![CDATA[salary]]></category>
		<category><![CDATA[sql functions]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=77</guid>
		<description><![CDATA[Oracle Functions explained]]></description>
			<content:encoded><![CDATA[<p>Oracle functions are very handy utilities to help you massage a result set to conform to your requirements, 		whether you are selecting, inserting, deleting or updating.</p>
<p>Below is a list of some commonly used sql functions, with an example of        each:</p>
<ul class="medium">
<li><a href="#01">add_months</a></li>
<li><a href="#02">avg</a></li>
<li><a href="#03">ceil</a></li>
<li><a href="#04">chr</a></li>
<li><a href="#05">concat</a></li>
<li><a href="#06">count </a></li>
<li><a href="#07">decode</a></li>
<li><a href="#08">dump</a></li>
<li><a href="#10">floor</a></li>
<li><a href="#11">greatest</a></li>
<li><a href="#12">initcap</a></li>
<li><a href="#13">instr</a></li>
<li><a href="#15">last_day</a></li>
<li><a href="#16">least</a></li>
<li><a href="#17">length</a></li>
<li><a href="#18">lower</a></li>
<li><a href="#19">lpad</a></li>
<li><a href="#20">ltrim</a></li>
<li><a href="#21">max</a></li>
<li><a href="#22">min</a></li>
<li><a href="#22a">mod</a></li>
<li><a href="#23">months_between</a></li>
<li><a href="#24">next_day</a></li>
<li><a href="#25">nullif</a></li>
<li><a href="#26">nvl</a></li>
<li><a href="#27">nvl2</a></li>
<li><a href="#29">replace</a></li>
<li><a href="#30">round </a></li>
<li><a href="#31">rpad</a></li>
<li><a href="#32">rtrim</a></li>
<li><a href="#33">sqrt</a></li>
<li><a href="#34">substr</a></li>
<li><a href="#35">sum</a></li>
<li><a href="#35a">sysdate</a></li>
<li><a href="#36">to_char </a></li>
<li><a href="#37">to_date</a></li>
<li><a href="#38">to_number</a></li>
<li><a href="#39">translate</a></li>
<li><a href="#40">trim</a></li>
<li><a href="#41">trunc </a></li>
<li><a href="#42">upper</a></li>
</ul>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="01" name="01"></a><br />
add_months</h3>
<p>Returns the supplied date with the requested number of months added to it.<br />
If the supplied date has a day value which is larger than the maximum number of days<br />
in the resulting month, the result is the last day of that month.</p>
<div id="textbox">
<div>SQL&gt; select sysdate from dual;</p>
<p>SYSDATE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
25-dec-2007 23:41:50</p>
<p>SQL&gt; select add_months(sysdate,1) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
25-jan-2008 23:41:52</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="02" name="02"></a><br />
avg</h3>
<p>Returns the average of a series of numbers.</p>
<div id="textbox">
<div>SQL&gt; select salary from employees;</p>
<p>SALARY<br />
&#8212;&#8212;&#8212;-<br />
20000<br />
30000<br />
30000<br />
10000</p>
<p>SQL&gt; select avg(salary) &#8220;result&#8221;  from employees;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8211;<br />
22500</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="03" name="03"></a><br />
ceil</h3>
<p>Returns the smallest integer larger than the supplied argument.<br />
Opposite of sql function: <a href="#10">floor</a>.</p>
<div id="textbox">
<div>SQL&gt; select 99.5, ceil(99.5) &#8220;result&#8221; from dual;</p>
<p>99.5     result<br />
&#8212;- &#8212;&#8212;&#8212;-<br />
99.5        100</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="04" name="04"></a><br />
chr</h3>
<p>Returns the character equivalent of the supplied integer.</p>
<div id="textbox">
<div>SQL&gt; select chr(79)||chr(82)||chr(65)||chr(67)||chr(76)||chr(69) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
ORACLE</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="05" name="05"></a><br />
concat</h3>
<p>Returns the first argument concatenated with the second argument.<br />
The result&#8217;s dataype will depend on the datatype of the arguments.<br />
I prefer to use the two pipe symbols (||) to concatenate.</p>
<div id="textbox">
<div>SQL&gt; select concat(&#8216;data&#8217;,'base&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8211;<br />
database</p>
<p>SQL&gt; select &#8216;data&#8217;||&#8217;base&#8217; &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8211;<br />
database</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="06" name="06"></a><br />
count</h3>
<p>Returns the number of rows as requested by the query, either all rows or only distinct values.<br />
By specifying *, it will return all rows including duplicates and nulls.<br />
If no rows match your query, count will return 0. (never null)</p>
<div id="textbox">
<div>SQL&gt; select count(*) &#8220;result&#8221; from emp;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
14</p>
<p>SQL&gt; select job &#8220;result&#8221; from emp;</p>
<p>result<br />
&#8212;&#8212;&#8212;<br />
CLERK<br />
SALESMAN<br />
SALESMAN<br />
MANAGER<br />
SALESMAN<br />
MANAGER<br />
MANAGER<br />
ANALYST<br />
PRESIDENT<br />
SALESMAN<br />
CLERK<br />
CLERK<br />
ANALYST<br />
CLERK</p>
<p>14 rows selected.</p>
<p>SQL&gt; select count(distinct job) &#8220;result&#8221; from emp ;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
5</p>
<p>SQL&gt; select count(*) &#8220;result&#8221; from emp where job = &#8216;VP&#8217;;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
0</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="07" name="07"></a><br />
decode</h3>
<p>The oracle decode function takes up to 255 argument sets and returns the relevant result depending on the value found.<br />
This is similar to the &#8216;case&#8217; statement in other languages.<br />
The last argument is what will be returned if no match is found in the decode statement.</p>
<div id="textbox">
<div>SQL&gt; select deptno &#8220;dn&#8221; , decode(deptno,10,&#8217;ten&#8217;,20,&#8217;twenty&#8217;,30,&#8217;thirty&#8217;,'other&#8217;) &#8220;result&#8221; from dept;</p>
<p>dn result<br />
&#8211; &#8212;&#8212;<br />
10    ten<br />
20    twenty<br />
30    thirty<br />
40    other</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="08" name="08"></a><br />
dump</h3>
<p>Returns a  string  representing the argument&#8217;s datatype code, byte length and internal representation.<br />
Very handy command if you are hunting for unexpected or hidden characters in your data.</p>
<div id="textbox">
<div>SQL&gt; select dump(&#8216;cat&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Typ=96 Len=3: 99,97,116</p>
<p>SQL&gt; select dump(&#8216;cat &#8216;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Typ=96 Len=4: 99,97,116,32</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="10" name="10"></a><br />
floor</h3>
<p>Returns an integer equal to or 1 less than the argument.<br />
Opposite of oracle function : <a href="#03">ceil</a>.</p>
<div id="textbox">
<div>SQL&gt; select 99.5, floor(99.5) &#8220;result&#8221; from dual;</p>
<p>99.5     result<br />
&#8212;- &#8212;&#8212;&#8212;-<br />
99.5         99</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="11" name="11"></a><br />
greatest</h3>
<p>Returns greatest ranking argument out of a list of arguments.<br />
The ranking is determined by the value of the numerical codes of the whole character string.<br />
Opposite of oracle function : <a href="#16">least</a>.</p>
<div id="textbox">
<div>SQL&gt; select greatest(&#8216;oracle&#8217;,'oracle10G&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;<br />
oracle10G</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="12" name="12"></a><br />
initcap</h3>
<p>Returns the string with each word&#8217;s first letter capitalized.<br />
Similar to oracle functions : <a href="#18">lower</a> and <a href="#42">upper</a></p>
<div id="textbox">
<div>SQL&gt; select initcap(&#8216;oracle database tips&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Oracle Database Tips</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="13" name="13"></a><br />
instr</h3>
<p>Returns the first position of a string inside another string.<br />
The 1st argument is the string to be searched.<br />
The 2nd argument specifies the character or string to search for.<br />
The 3rd argument allows you to specify from which character position to start searching.<br />
The 4th argument allows you to specify which occurence of the search string to return.</p>
<div id="textbox">
<div>SQL&gt; select instr(&#8216;package&#8217;,'a&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
2</p>
<p>SQL&gt; select instr(&#8216;package&#8217;,'a&#8217;,3,1) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
5</p>
<p>SQL&gt; select instr(&#8216;package&#8217;,'a&#8217;,1,2) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-</p>
<p>5</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="15" name="15"></a><br />
last_day</h3>
<p>Returns the last day&#8217;s date of the supplied date&#8217;s month.</p>
<div id="textbox">
<div>SQL&gt; select sysdate, last_day(sysdate) &#8220;result &#8221; from            dual;</p>
<p>SYSDATE                      result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;          &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
27-dec-2007 15:49:27   31-dec-2007 15:49:27</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="16" name="16"></a><br />
least</h3>
<p>Returns the least or smallest ranking argument out of a list of arguments.<br />
The ranking is determined by the value of the numerical codes of the whole character string.<br />
Opposite of oracle function : <a href="#11">greatest</a></p>
<div id="textbox">
<div>SQL&gt; select least(&#8216;oracle&#8217;,'oracle10G&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
oracle</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="17" name="17"></a><br />
length</h3>
<p>Returns the length (as an integer) of the supplied argument.</p>
<div id="textbox">
<div>SQL&gt; select length(&#8216;oracle database&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
15</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="18" name="18"></a><br />
lower</h3>
<p>Returns the argument in lower case.<br />
Similar to oracle functions : <a href="#42">upper</a> and <a href="#12">initcap</a></p>
<div id="textbox">
<div>SQL&gt; select lower(&#8216;ORACLE&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
oracle</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="19" name="19"></a><br />
lpad</h3>
<p>Returns the first argument, left-padded by the third argument, so that the complete string is as long as specified by the second argument.<br />
If you do not supply the third argument, blank spaces are used for padding.<br />
Similar to oracle function : <a href="#31">rpad</a></p>
<div id="textbox">
<div>SQL&gt; select lpad(&#8216;oracle&#8217;,10,&#8217;*') &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
****oracle</p>
<p>SQL&gt; select lpad(&#8216;oracle&#8217;,10) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
oracle</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="20" name="20"></a><br />
ltrim</h3>
<p>Removes the second argument from the first argument.<br />
If you do not supply the second argument, it will remove blank spaces.<br />
Similar to oracle function: <a href="#32">rtrim</a></p>
<div id="textbox">
<div>SQL&gt; select ltrim(&#8216;oracle database&#8217;,'orac&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8211;<br />
le database</p>
<p>SQL&gt; select ltrim(&#8216;    oracle&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
oracle</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="21" name="21"></a><br />
max</h3>
<p>Returns the largest of a series of numbers.<br />
Similar to oracle function :  <a href="#22">min</a></p>
<div id="textbox">
<div>SQL&gt; select grade from salgrade;</p>
<p>GRADE<br />
&#8212;&#8212;&#8212;-<br />
1<br />
2<br />
3<br />
4<br />
5</p>
<p>SQL&gt; select max(grade) &#8220;result&#8221; from salgrade;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
5</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="22" name="22"></a><br />
min</h3>
<p>Returns the smallest in a series of numbers.<br />
Similar to oracle function : <a href="#21">max</a></p>
<div id="textbox">
<div>SQL&gt; select grade from salgrade;</p>
<p>GRADE<br />
&#8212;&#8212;&#8212;-<br />
1<br />
2<br />
3<br />
4<br />
5</p>
<p>SQL&gt; select min(grade) &#8220;result&#8221; from salgrade;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
1</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="22a" name="22a"></a><br />
mod</h3>
<p>Returns the remainder of the first argument divided by the second argument.<br />
The result is <a href="#10">floor</a>-ed.</p>
<div id="textbox">
<div>SQL&gt; select mod(222,23) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
15</p></div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="23" name="23"></a><br />
months_between</h3>
<p>This date-oriented oracle function returns the number of months between two dates as a fraction.</p>
<div id="textbox">
<div>SQL&gt; select months_between(sysdate+320 ,sysdate) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
10.483871</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="24" name="24"></a><br />
next_day</h3>
<p>Returns date of the day of the week (supplied as the second argument) after the date of the first argument.<br />
The second argument is specified as the name of a weekday.</p>
<div id="textbox">
<div>SQL&gt; select next_day(&#8217;01-JAN-2008&#8242;,&#8217;SUNDAY&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
06-jan-2008 00:00:00</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="25" name="25"></a><br />
nullif</h3>
<p>Returns null if the first and second argument are equal, if they are unequal, it will return the first argument.</p>
<div id="textbox">
<div>SQL&gt; select nullif(1,1) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-</p>
<p>SQL&gt; select nullif(1,2) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
1</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="26" name="26"></a><br />
nvl</h3>
<p>Returns the second argument if the first argument is null.<br />
Otherwise, the first argument is returned.<br />
Similar to oracle function : <a href="#27">nvl2</a></p>
<div id="textbox">
<div>SQL&gt; select nvl(null,&#8217;no value&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8211;<br />
no value</p>
<p>SQL&gt; select nvl(&#8216;some value&#8217;,'no value&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
some value</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="27" name="27"></a><br />
nvl2</h3>
<p>This function is an extension to nvl by allowing you to specify a value to return if the argument to be checked is null.<br />
So, nvl2 will return the third argument if the first argument is null and will return the second argument if the first argument is not null.<br />
Similar to oracle function : <a href="#26">nvl</a></p>
<div id="textbox">
<div>SQL&gt; select nvl2(null,&#8217;has value&#8217;,'no value&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8211;<br />
no value</p>
<p>SQL&gt; select nvl2(&#8216;some value&#8217;,'has value&#8217;,'no value&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;<br />
has value</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="29" name="29"></a><br />
replace</h3>
<p>Returns the first argument with every occurence of the second argument replaced with the third argument.<br />
If the third argument is left out, the second argument is removed from the first argument.<br />
If the second argument is null, then the first argument is returned unmodified.</p>
<div id="textbox">
<div>SQL&gt; select replace(&#8216;down in the creek&#8217;,'down in&#8217;,'up&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;<br />
up the creek</p>
<p>SQL&gt; select replace(&#8216;down in the creek&#8217;,'down in&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
the creek</p>
<p>SQL&gt; select replace(&#8216;down in the creek&#8217;,null,&#8217;up&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
down in the creek</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="30" name="30"></a><br />
round (number)</h3>
<p>Returns the first argument rounded to the number of places after the decimal point as specified by the second argument.<br />
If the second argument is not specified, then the first argument is rounded to 0 places after the decimal point.<br />
If the result is n.5, round will round up to the next integer, if the result is -n.5, it will round down to the next integer.</p>
<div id="textbox">
<div>SQL&gt; select round(8.345,2) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
8.35</p>
<p>SQL&gt; select round(8.345) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
8</p>
<p>SQL&gt; select round(8.5) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
9</p>
<p>SQL&gt; select round(-8.5) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
-9</p></div>
</div>
<h3>
round (date)</h3>
<p>This will always return a date.<br />
The format of the second argument determines the timeperiod it will round to, like YEAR, MONTH, DAY, HH and MI.<br />
If you do not specify a second argument, the format defaults to day.</p>
<div id="textbox">
<div>SQL&gt; select sysdate &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
04-jan-2008 15:34:19</p>
<p>SQL&gt; select round(sysdate) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
05-jan-2008 00:00:00</p>
<p>SQL&gt; select round(sysdate,&#8217;YYYY&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
01-jan-2008 00:00:00</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="31" name="31"></a><br />
rpad</h3>
<p>Returns the first argument, right-padded by the third argument, so that the complete string is as long as specified by the second argument.<br />
If you do not supply the third argument, blank spaces are used for padding.<br />
Similar to oracle function : <a href="#19">lpad</a></p>
<div id="textbox">
<div>SQL&gt; select rpad(&#8216;star status &#8216;,15,&#8217;*') &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;<br />
star status ***</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="32" name="32"></a><br />
rtrim</h3>
<p>Removes the second argument from the first argument.<br />
If you do not supply the second argument, it will remove blank spaces.<br />
Similar to oracle function : <a href="#20">ltrim</a></p>
<div id="textbox">
<div>SQL&gt; select rtrim(&#8216;oracle***&#8217;,'*&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;<br />
oracle</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="33" name="33"></a><br />
sqrt</h3>
<p>Returns the square root of the argument.</p>
<div id="textbox">
<div>SQL&gt; select sqrt(16) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
4</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="34" name="34"></a><br />
substr</h3>
<p>This very useful sql function returns the part of the first argument, determined by what you specify as the second and third arguments.<br />
The second argument tells Oracle from which character position to start counting.<br />
It can contain a positive or negative value.<br />
The third argument determines the number of characters to select.<br />
If you do not supply this argument, all characters until the end are selected.</p>
<p>Read up more about this very useful oracle function :<br />
<a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Ffunctions162.htm%23i87066&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_functions.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions162.htm#i87066" target="_blank">Oracle          online documentation : SQL Reference, substr</a></p>
<div id="textbox">
<div>SQL&gt; select substr(&#8216;oracle functions&#8217;,8,8) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;-<br />
function</p>
<p>SQL&gt; select substr(&#8216;oracle functions&#8217;,8) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
functions</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="35" name="35"></a><br />
sum</h3>
<p>Returns the sum of a range of numbers.</p>
<div id="textbox">
<div>SQL&gt; select sal from emp;</p>
<p>SAL<br />
&#8212;&#8212;&#8212;-<br />
800<br />
1600<br />
1250<br />
2975<br />
1250<br />
2850<br />
2450<br />
3000<br />
5000<br />
1500<br />
1100<br />
950<br />
3000<br />
1300</p>
<p>14 rows selected.</p>
<p>SQL&gt; select sum(sal) &#8220;result&#8221; from emp;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
29025</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="35a" name="35a"></a><br />
sysdate</h3>
<p>Returns the current date and time of the local database server&#8217;s operating system.<br />
You will see the date format as it is specified by the NLS_DATE_FORMAT<br />
database initialization parameter.<br />
You can set NLS_DATE_FORMAT for your session to overwrite the database&#8217;s default value.<br />
Alternatively, you can convert sysdate to a character datatype using the <a href="#36">to_char</a> function.</p>
<div id="textbox">
<div>SQL&gt; select sysdate &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
05-jan-2008 16:57:11</p>
<p>SQL&gt; alter session set nls_date_format=&#8217;dd/mm/yyyy hh24-mi&#8217;;</p>
<p>Session altered.</p>
<p>SQL&gt; select sysdate &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
05/01/2008 16-58</p>
<p>SQL&gt; select to_char(sysdate,&#8217;dd/mon/yyyy hh24:mi:ss&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
05/jan/2008 16:58:36</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="36" name="36"></a><br />
to_char</h3>
<p>Converts the argument to a character datatype, using the format specified by the second argument.<br />
You can convert number, date and CLOB datatypes.</p>
<p>Read up more about format models here:<br />
<a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fsql_elements004.htm%23i34510&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_functions.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34510" target="_blank">Oracle          online documentation : SQL Reference, format models</a></p>
<div id="textbox">
<div>SQL&gt; select to_char(sal,&#8217;L99G999D99MI&#8217;) &#8220;result&#8221; from emp;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
$800.00<br />
$1,600.00<br />
$1,250.00<br />
$2,975.00<br />
$1,250.00<br />
$2,850.00<br />
$2,450.00<br />
$3,000.00<br />
$5,000.00<br />
$1,500.00<br />
$1,100.00<br />
$950.00<br />
$3,000.00<br />
$1,300.00</p>
<p>SQL&gt; select to_char(sysdate,&#8217;DD-MON-YYYY hh24:mi:ss&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
05-JAN-2008 16:42:27</p>
<p>select to_char(clob_column) &#8220;result&#8221; from large_table where itemno = 469;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed<br />
diam nonumy eirmod tempor invidunt ut labore et dolore magna<br />
aliquyam erat, sed diam voluptua. At vero eos et accusam et<br />
justo duo dolores et ea rebum. Stet clita kasd gubergren, no<br />
sea takimata sanctus est Lorem ipsum dolor sit amet.</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="37" name="37"></a><br />
to_date</h3>
<p>Converts a character string to a date datatype.<br />
If the character string is already in the default format, you do not need to specify a format as the second argument.<br />
The default format is specified by initialization parameter NLS_TERRITORY or can be set by NLS_DATE_FORMAT.</p>
<p>Read up more about format models here:<br />
<a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fsql_elements004.htm%23i34510&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_functions.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34510" target="_blank">Oracle          online documentation : SQL Reference, oracle function format models</a></p>
<div id="textbox">
<div>SQL&gt; select * from nls_session_parameters where parameter = &#8216;NLS_DATE_FORMAT&#8217;;</p>
<p>PARAMETER                VALUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
NLS_DATE_FORMAT     dd-mon-yyyy</p>
<p>SQL&gt; select to_date(&#8217;01-jan-2008&#8242;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8211;<br />
01-jan-2008</p>
<p>SQL&gt; select to_date(&#8217;01/01/2008&#8242;) &#8220;result&#8221; from dual;<br />
select to_date(&#8217;01/01/2008&#8242;) &#8220;result&#8221; from dual<br />
*<br />
ERROR at line 1:<br />
ORA-01843: not a valid month</p>
<p>SQL&gt; select to_date(&#8217;01/01/2008&#8242;,&#8217;DD/MM/YYYY&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8211;<br />
01-jan-2008</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="38" name="38"></a><br />
to_number</h3>
<p>Converts a character datatype to a number datatype<br />
The second argument supplies the format needed to do the conversion.</p>
<p>Read up more about format models here:<br />
<a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fsql_elements004.htm%23i34510&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_functions.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34510" target="_blank">Oracle          online documentation : SQL Reference, format models</a></p>
<div id="textbox">
<div>SQL&gt; select to_number(&#8216;$800.00&#8242;,&#8217;L9G999D99&#8242;) &#8220;result&#8221;  from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
800</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="39" name="39"></a><br />
translate</h3>
<p>Returns a string which replaces all occurences of the characters in the second argument<br />
with the characters of the third argument.<br />
If the second argument contains more characters than the third argument,<br />
the extra characters are removed from the result.</p>
<div id="textbox">
<div>SQL&gt; select translate(&#8216;November&#8217;,'Nov&#8217;,'Dec&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8211;<br />
December</p>
<p>SQL&gt; select translate(&#8216;September&#8217;,'Sept&#8217;,'Dec&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8211;<br />
December</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="40" name="40"></a><br />
trim</h3>
<p>Returns the third argument with the leading, ending or both sides of the argument&#8217;s characters trimmed.<br />
The first argument specifies which side to trim from.<br />
Values can be &#8216;LEADING&#8217;,'TRAILING&#8217; or &#8216;BOTH&#8217;.<br />
If null, both sides are trimmed.<br />
The second argument specifies which character to trim. If null, blanks are assumed.<br />
The third argument takes the form : FROM &lt; source &gt; which can be a column name.</p>
<div id="textbox">
<div>SQL&gt; select ename from emp where ename = &#8216;FORD&#8217;;</p>
<p>ENAME<br />
&#8212;&#8212;&#8212;-<br />
FORD</p>
<p>SQL&gt; select trim(leading &#8216;F&#8217; from ename) &#8220;result&#8221; from emp where ename = &#8216;FORD&#8217;;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
ORD</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="41" name="41"></a><br />
trunc(number)</h3>
<p>Returns the first argument truncated to the number of decimal places determined by the second argument.<br />
If the second argument is not specified, Oracle assumes 0.</p>
<div id="textbox">
<div>SQL&gt; select trunc(18.456,2) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
18.45</p>
<p>SQL&gt; select trunc(18.456) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;-<br />
18</p></div>
</div>
<h3><a id="41" name="41"></a><br />
trunc(date)</h3>
<p>Returns the date truncated to the day specified by the second argument&#8217;s format.<br />
The format of the second argument determines the timeperiod it will truncate to, like YEAR, MONTH, DAY, HH and MI.<br />
If you do not specify a second argument, the format defaults to DAY.</p>
<div id="textbox">
<div>SQL&gt; select sysdate &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8211;<br />
05-jan-2008</p>
<p>SQL&gt; select trunc(sysdate,&#8217;YEAR&#8217;) &#8220;result&#8221; from dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8211;<br />
01-jan-2008</p></div>
</div>
<div><a href="#" target="_top">top of page</a></div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<h3><a id="42" name="42"></a><br />
upper</h3>
<p>Returns the argument with all characters in upper case.<br />
Similar to oracle functions : <a href="#18">lower</a> and <a href="#12">initcap</a></p>
<div id="textbox">
<div>SQL&gt; select upper(&#8216;oracle functions&#8217;) &#8220;result&#8221; from            dual;</p>
<p>result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
ORACLE FUNCTIONS</p></div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<p><!--  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  --></p>
<h3>Recommended reading for more information on oracle functions :</h3>
<p><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Ffunctions.htm%23i1482196&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_functions.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions.htm#i1482196" target="_blank">Oracle          online documentation: SQL Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/oracle-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Subquery</title>
		<link>http://oracle-database-tips.com/wp/sql/oracle-subquery</link>
		<comments>http://oracle-database-tips.com/wp/sql/oracle-subquery#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:07:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[accounting]]></category>
		<category><![CDATA[better solution]]></category>
		<category><![CDATA[boston]]></category>
		<category><![CDATA[emp]]></category>
		<category><![CDATA[ford]]></category>
		<category><![CDATA[illustration]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[oracle subquery]]></category>
		<category><![CDATA[subquery sql]]></category>
		<category><![CDATA[subquery syntax]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=74</guid>
		<description><![CDATA[Oracle Subquery syntax and examples]]></description>
			<content:encoded><![CDATA[<p><strong>Contents</strong></p>
<ul>
<li><a href="#0">Definition</a></li>
<li><a href="#1">Simple subquery</a></li>
<li><a href="#correlated">Correlated subquery</a></li>
<li><a href="#update">Update with correlated subquery</a></li>
<li><a href="#delete">Delete with correlated subquery</a></li>
</ul>
<p><a id="0" name="0"></a><br />
<strong>Definition</strong></p>
<p>A subquery is basically a select clause which is used instead of another statement.</p>
<p>For example : Have a look at the following 2 tables : DEPT and EMP</p>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept order by deptno;

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

SQL&gt; select empno,ename,job,sal,deptno from emp;

     EMPNO ENAME      JOB              SAL     DEPTNO
---------- ---------- --------- ---------- ----------
      7369 SMITH      CLERK            800         20
      7499 ALLEN      SALESMAN        1600         30
      7521 WARD       SALESMAN        1250         30
      7566 JONES      MANAGER         2975         20
      7654 MARTIN     SALESMAN        1250         30
      7698 BLAKE      MANAGER         2850         30
      7782 CLARK      MANAGER         2450         10
      7788 SCOTT      ANALYST         3000         20
      7839 KING       PRESIDENT       5000         10
      7844 TURNER     SALESMAN        1500         30
      7876 ADAMS      CLERK           1100         20
      7900 JAMES      CLERK            950         30
      7902 FORD       ANALYST         3000         20
      7934 MILLER     CLERK           1300         10

14 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><a id="1" name="1"></a><br />
<strong>Simple Oracle subquery</strong></p>
<p>A simple subquery is evaluated once for each table.</p>
<p>You would like to select all employees whose department is located in Chicago.</p>
<p>A join would be a better solution for this select,<br />
but for the purposes of illustration we will use a subquery.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">
SQL&gt; select empno,ename,job,sal,deptno from emp where
     deptno in (select deptno from dept
	 where loc = 'CHICAGO');

     EMPNO ENAME      JOB              SAL     DEPTNO
---------- ---------- --------- ---------- ----------
      7900 JAMES      CLERK            950         30
      7844 TURNER     SALESMAN        1500         30
      7698 BLAKE      MANAGER         2850         30
      7654 MARTIN     SALESMAN        1250         30
      7521 WARD       SALESMAN        1250         30
      7499 ALLEN      SALESMAN        1600         30

6 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
You can use a subquery in the place of a table name in the &#8216;from&#8217; clause.</p>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; Select ename, deptno from
     (select ename, deptno from emp
	 where job = 'CLERK' )
     where
     deptno &gt; 20;

ENAME          DEPTNO
---------- ----------
JAMES              30</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
You can even replace a column name with a subquery:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select ename,
            (select max(sal) from emp) "maxsal" ,
            sal,
            ((select max(sal) from emp ) - sal )
			"difference"  from emp;

ENAME          maxsal        SAL difference
---------- ---------- ---------- ----------
SMITH            5000        800       4200
ALLEN            5000       1600       3400
WARD             5000       1250       3750
JONES            5000       2975       2025
MARTIN           5000       1250       3750
BLAKE            5000       2850       2150
CLARK            5000       2450       2550
SCOTT            5000       3000       2000
KING             5000       5000          0
TURNER           5000       1500       3500
ADAMS            5000       1100       3900
JAMES            5000        950       4050
FORD             5000       3000       2000
MILLER           5000       1300       3700

14 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
<a id="correlated" name="correlated"></a><br />
<strong>Correlated Oracle subquery</strong></p>
<p>A correlated Oracle subquery is evaluated once FOR EACH ROW as opposed to a normal subquery which is evaluated only once for each table.</p>
<p>You can reference the outer query inside the correlated subquery using an alias which makes it so handy to use.</p>
<p>Let&#8217;s select all employees whose salary is less than the average of all the employees&#8217; salaries in the same department.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select ename ,sal ,deptno from emp a where
     a.sal &lt; (select avg(sal) from emp b
	           where a.deptno = b.deptno)
     order by deptno;

ENAME             SAL     DEPTNO
---------- ---------- ----------
CLARK            2450         10
MILLER           1300         10
SMITH             800         20
ADAMS            1100         20
WARD             1250         30
MARTIN           1250         30
TURNER           1500         30
JAMES             950         30

8 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
<a id="update" name="update"></a><br />
<strong>Using a correlated subquery in an update</strong></p>
<p>Let&#8217;s give these people (whose salary is less than their department&#8217;s average)  a raise.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">
SQL&gt; select ename, sal, deptno  from emp
     order by deptno, ename;

ENAME             SAL     DEPTNO
---------- ---------- ----------
CLARK            2450         10
KING             5000         10
MILLER           1300         10
ADAMS            1100         20
FORD             3000         20
JONES            2975         20
SCOTT            3000         20
SMITH             800         20
ALLEN            1600         30
BLAKE            2850         30
JAMES             950         30
MARTIN           1250         30
TURNER           1500         30
WARD             1250         30

14 rows selected.

SQL&gt;  UPDATE emp a
      set sal = (select avg(sal)
                from emp b
	        where
	        a.deptno = b.deptno)
      where sal &lt;
	   (select avg(sal) from emp c
	   where a.deptno = c.deptno);

8 rows updated.

SQL&gt; select ename, sal, deptno  from emp
     order by deptno, ename;

ENAME             SAL     DEPTNO
---------- ---------- ----------
CLARK         2916.67         10
KING             5000         10
MILLER        2916.67         10
ADAMS            2175         20
FORD             3000         20
JONES            2975         20
SCOTT            3000         20
SMITH            2175         20
ALLEN            1600         30
BLAKE            2850         30
JAMES         1566.67         30
MARTIN        1566.67         30
TURNER        1566.67         30
WARD          1566.67         30

14 rows selected.

SQL&gt; commit;

Commit complete.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><a id="delete" name="delete"></a><br />
<strong>Using a correlated subquery in a delete</strong></p>
<p>Let&#8217;s delete the highest earning employees in each department.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">
SQL&gt;  delete from emp a where
      a.sal = (select max(sal) from emp b
	  where a.deptno = b.deptno);

4 rows deleted.

SQL&gt; select ename, sal, deptno  from emp
     order by deptno, ename;

ENAME             SAL     DEPTNO
---------- ---------- ----------
CLARK         2916.67         10
MILLER        2916.67         10
ADAMS            2175         20
JONES            2975         20
SMITH            2175         20
ALLEN            1600         30
JAMES         1566.67         30
MARTIN        1566.67         30
TURNER        1566.67         30
WARD          1566.67         30

10 rows selected.

SQL&gt; commit;

Commit complete.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
Lastly: do not forget to commit to make your changes permanent when using the oracle subquery statement.<br />
<!-- ============================================================================================================================================================ --></p>
<h3>Recommended reading:</h3>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fappdev.102%2Fb14261%2Fsqloperations.htm%23i3317&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_subquery.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i3317" target="_blank">Oracle Online Documentation: SQL Reference, Using Subqueries</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/oracle-subquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Delete syntax</title>
		<link>http://oracle-database-tips.com/wp/sql/oracle-delete-syntax</link>
		<comments>http://oracle-database-tips.com/wp/sql/oracle-delete-syntax#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:03:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[delete syntax]]></category>
		<category><![CDATA[finance]]></category>
		<category><![CDATA[melbourne]]></category>
		<category><![CDATA[oracle delete]]></category>
		<category><![CDATA[restriction]]></category>
		<category><![CDATA[sql delete]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=72</guid>
		<description><![CDATA[The Oracle Delete statement allows you to remove rows from a table.]]></description>
			<content:encoded><![CDATA[<p>Always test these &#8216;oracle delete&#8217; commands on a test server<br />
before implementing them on a production server.</p>
<p>The Oracle Delete statement allows you to remove rows from a table.</p>
<p>The syntax is : delete from<br />
(where );</p>
<p>If you specify the delete statement without the where clause, you will delete all rows from a table.</p>
<p>Specifying the where clause will restrict the deletion to the rows which match the restriction clause.</p>
<p>Here is the sample table:</p>
<p>SQL&gt; select * from dept order by deptno;</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<br />
50 MARKETING      MELBOURNE<br />
60 IT             HARTORD<br />
70 CALLCENTRE<br />
80 SUPPORT        NONE<br />
90                BOISE<br />
91 SHIPPING       DETROIT<br />
92 FINANCE        DETROIT</p>
<p>11 rows selected.</p>
<p>Let&#8217;s delete all rows that are located in Detroit.</p>
<p>SQL&gt; delete from dept where loc = &#8216;DETROIT&#8217;;</p>
<p>2 rows deleted.</p>
<p>SQL&gt; select * from dept order by deptno;</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<br />
50 MARKETING      MELBOURNE<br />
60 IT             HARTORD<br />
70 CALLCENTRE<br />
80 SUPPORT        NONE<br />
90                BOISE</p>
<p>9 rows selected.</p>
<p>Now let&#8217;s select all rows that have a null value in either the dname column or the deptno column.</p>
<p>SQL&gt; delete from dept where dname is null or loc is null;</p>
<p>2 rows deleted.</p>
<p>SQL&gt; select * from dept order by deptno;</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<br />
50 MARKETING      MELBOURNE<br />
60 IT             HARTORD<br />
80 SUPPORT        NONE</p>
<p>7 rows selected.</p>
<p>Now let&#8217;s delete all the remaining rows from this table:</p>
<p>SQL&gt; delete from dept;</p>
<p>7 rows deleted.</p>
<p>SQL&gt; select * from dept order by deptno;</p>
<p>no rows selected</p>
<p>Lastly: do not forget to commit to make your changes permanent after you use the Delete statement.</p>
<p>Recommended reading:</p>
<p><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fstatements_8005.htm%23i2117787&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_delete.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_8005.htm#i2117787" target="_blank">Oracle Online Documentation: SQL Reference, Delete statement</a></p>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/oracle-delete-syntax/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>Oracle Insert</title>
		<link>http://oracle-database-tips.com/wp/sql/oracle-insert</link>
		<comments>http://oracle-database-tips.com/wp/sql/oracle-insert#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[abbreviation]]></category>
		<category><![CDATA[column names]]></category>
		<category><![CDATA[desc]]></category>
		<category><![CDATA[insert syntax]]></category>
		<category><![CDATA[oracle insert]]></category>
		<category><![CDATA[sql insert]]></category>
		<category><![CDATA[subquery]]></category>
		<category><![CDATA[table contents]]></category>
		<category><![CDATA[varchar2]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=68</guid>
		<description><![CDATA[The Oracle Insert statement allows you to add data to a table using the following syntax:]]></description>
			<content:encoded><![CDATA[<p><strong>Examples and explanation</strong></p>
<p>The Oracle Insert statement allows you to add data to a table.</p>
<p>Contents :</p>
<ul>
<li> <a href="#nocolumn"> Inserting without specifying column names</a></li>
<li><a href="#column"> Inserting by specifying column names</a></li>
<li> <a href="#default"> Insert a column&#8217;s default value</a></li>
<li> <a href="#null"> Inserting a null value</a></li>
<li> <a href="#subquery"> Inserting multiple rows by means of a subquery</a></li>
</ul>
<p>The syntax is : insert into &lt;table_name&gt; ( &lt;column list&gt;)          values (&lt;values list&gt;);</p>
<p>You do not have to specify the column names if your value list is in          the same order as the columns of the table, but it is best to always specify          the column names.</p>
<p><strong>Sample table for use in the Oracle Insert syntax tutorial:</strong><br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><a id="nocolumn" name="nocolumn"></a><strong>No column list</strong></p>
<p>When you do not specify the column list, you can use the <em>values</em> clause immediately after<br />
the <em>table</em> clause, but Oracle will expect the values to match the column datatypes,<br />
so you must make sure that the values are in the same order as the table&#8217;s columns.</p>
<p>To see what the order of a table&#8217;s columns is,<br />
use the &#8216;DESCRIBE&#8217; statement or its abbreviation &#8216;desc&#8217; :<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; describe dept
 Name                   Null?    Type
 ---------------------- -------- ---------------

 DEPTNO                          NUMBER(2)
 DNAME                           VARCHAR2(14)
 LOC                             VARCHAR2(13)</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; insert into dept values
     (50,'MARKETING','MELBOURNE');

1 row created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      MELBOURNE</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><a id="column" name="column"></a><strong>Using a column list </strong><br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; insert into dept (deptno,dname,loc)
     values (60,'IT','HARTFORD');

1 row created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      MELBOURNE
        60 IT             HARTFORD

6 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   -->Using a column list allows you to insert values for selected columns only:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; insert into dept (deptno,dname)
     values (70,'CALLCENTER');

1 row created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      MELBOURNE
        60 IT             HARTORD
        70 CALLCENTER

7 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <a id="default" name="default"></a><strong>Default values</strong><br />
You can choose to insert a column&#8217;s default value like this:<br />
Let&#8217;s first change the DEPT table to have a default value of &#8216;NONE&#8217; for          the location column:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; alter table dept modify (loc default 'NONE');

Table altered.

SQL&gt; insert into dept (deptno,dname,loc)
     values (80,'SUPPORT',DEFAULT);

1 row created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      MELBOURNE
        60 IT             HARTORD
        70 CALLCENTER
        80 SUPPORT        NONE

8 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <a id="null" name="null"></a><strong>Inserting a null value</strong></p>
<p>Use the &#8216;null&#8217; identifier to insert a null value instead of a real value.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; insert into dept (deptno,dname,loc)
     values (90,NULL,'BOISE');

1 row created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      MELBOURNE
        60 IT             HARTORD
        70 CALLCENTER
        80 SUPPORT        NONE
        90                BOISE

9 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <a id="subquery" name="subquery"></a><strong>Inserting multiple rows by means of a subquery</strong></p>
<p>Instead of adding one row at a time, here is an example of inserting          a number of rows by using a subquery:</p>
<p>We have another table called DEPT_MERGE with the same table structure          as DEPT and with rows which need to be added to DEPT.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept_merge order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        91 SHIPPING       DETROIT
        92 FINANCE        DETROIT

SQL&gt; insert into dept
  2  (select * from dept_merge);

2 rows created.

SQL&gt; commit;

Commit complete.

SQL&gt; select * from dept order by deptno;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
        50 MARKETING      MELBOURNE
        60 IT             HARTORD
        70 CALLCENTER
        80 SUPPORT        NONE
        90                BOISE
        91 SHIPPING       DETROIT
        92 FINANCE        DETROIT

11 rows selected.</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
Lastly: do not forget to commit to make your changes permanent after you use the Oracle Insert statement.</p>
<p><!-- ============================================================================================================================================================ --></p>
<h3>Recommended reading:</h3>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fstatements_9014.htm%23i2163698&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_insert.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#i2163698" target="_blank">Oracle Online Documentation: SQL Reference, Insert statement</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/oracle-insert/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle SQL Select</title>
		<link>http://oracle-database-tips.com/wp/sql/oracle-sql-select</link>
		<comments>http://oracle-database-tips.com/wp/sql/oracle-sql-select#comments</comments>
		<pubDate>Fri, 23 Oct 2009 10:55:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[boston time]]></category>
		<category><![CDATA[chicago operations]]></category>
		<category><![CDATA[correct syntax]]></category>
		<category><![CDATA[oracle select]]></category>
		<category><![CDATA[select syntax]]></category>
		<category><![CDATA[sql select]]></category>
		<category><![CDATA[synonym]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=64</guid>
		<description><![CDATA[This tutorial will show you how to use the correct syntax to query data in the Oracle database.]]></description>
			<content:encoded><![CDATA[<h1></h1>
<h3>How to query the Oracle database</h3>
<p>Always test these &#8216;select&#8217; commands on a test server<br />
before implementing them on a production server.</p>
<p>This tutorial will show you how to use the correct syntax to query data          in the Oracle database.</p>
<p>When you query an object, you could be querying a table, a synonym or          a view,<br />
but this will make no difference to the syntax you need to use or to the          result you will obtain.</p>
<p>A table consists of a number of columns and rows and your query          will be built so that you decide which rows and which columns to return.</p>
<p>The simplified syntax for the queries we&#8217;ll be using in this          tutorial is as follows:</p>
<p>select &lt;column list&gt; from &lt;table&gt; where &lt;row criteria&gt;          ;</p>
<p>For example: (log in as scott/tiger)</p>
<p>Table DEPT looks like this :</p>
<table border="1" cellspacing="0" cellpadding="0" width="400">
<tbody>
<tr>
<td width="73"><strong>DEPTNO </strong></td>
<td width="62"><strong>DNAME </strong></td>
<td width="57"><strong>LOC</strong></td>
</tr>
<tr>
<td>10</td>
<td>ACCOUNTING</td>
<td>NEW YORK</td>
</tr>
<tr>
<td>20</td>
<td>RESEARCH</td>
<td>DALLAS</td>
</tr>
<tr>
<td>30</td>
<td>SALES</td>
<td>CHICAGO</td>
</tr>
<tr>
<td>40</td>
<td>OPERATIONS</td>
<td>BOSTON</td>
</tr>
</tbody>
</table>
<p>There are 3 columns : DEPTNO, DNAME and LOC<br />
There are 4 rows.</p>
<p><strong>Column criteria</strong></p>
<p>Let&#8217;s query all columns and all rows:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select deptno, dname, loc from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> Time saving tip: use * instead of the whole column list if you plan to          return each column<br />
in the table:</p>
<p>Let&#8217;s only query the Location column in the table.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select loc from dept;

LOC
-------------
NEW YORK
DALLAS
CHICAGO
BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   -->Now let&#8217;s query both the DNAME and LOC columns from this table:<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select dname, loc from dept;

DNAME          LOC
-------------- -------------
ACCOUNTING     NEW YORK
RESEARCH       DALLAS
SALES          CHICAGO
OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <strong>Row criteria</strong></p>
<p>To specify only a subset of rows to be returned,<br />
you will use the WHERE clause.</p>
<p>Let&#8217;s query only the rows in the dept table belonging to the SALES department.<br />
We will query all columns.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept where dname = 'SALES';

    DEPTNO DNAME          LOC
---------- -------------- -------------
        30 SALES          CHICAGO</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   -->We could also decide to make the DEPTNO the criteria to deliver the same        result.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept where deptno = 30;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        30 SALES          CHICAGO</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   -->What if we want to query all rows related to departments that have department        numbers larger than 20 ?<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept where deptno &gt; 20;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> What if you want to make your <em>where</em> clause more complex ?</p>
<p>Let&#8217;s look for any rows that have &#8216;SALES&#8217; as a department name but also          any rows that have &#8216;BOSTON&#8217; as the location.</p>
<p>This means that<br />
any row contains the value &#8216;SALES&#8217; in the DNAME column,<br />
as well as<br />
any row containing the value &#8216;BOSTON&#8217; in the LOC column<br />
will be included in the result set.</p>
<p>You can do so by adding another section to the <em>where</em> clause and          using the &#8216;OR&#8217; term to glue them together.<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept
     where dname = 'SALES' or loc = 'BOSTON';

    DEPTNO DNAME          LOC
---------- -------------- -------------
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --><br />
If you want your result set to return only rows<br />
where the location is &#8216;BOSTON&#8217;<br />
and<br />
the department name is &#8216;SALES&#8217;,<br />
you will see 0 rows returned because no row has both those values for the        relevant columns :<br />
<!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; select * from dept
     where dname = 'SALES' and loc = 'BOSTON';

no rows</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <strong>Note on datatypes<br />
</strong> Your <em>where</em> clause will have to be aware of which type          of data you are using as query criteria.<br />
In other words, you must be sure to use the correct datatype in your <em>where</em> clause.</p>
<p>For example, DNAME is a varchar column, so you must put single quotes          around your query criteria.<br />
(Only number datatypes do not need single quotes)</p>
<p>If you try to specify SALES in your <em>where</em> clause like this          :</p>
<p><em>where dname = SALES;</em></p>
<p>you will receive an error:</p>
<p><em> ORA-00904: &#8220;SALES&#8221;: invalid identifier</em></p>
<p>because you are expected to supply single quotes around a varchar datatype          like this:</p>
<p><em> where dname = &#8216;SALES&#8217;;</em></p>
<p><strong>How do you know the datatype of a column in a table ?</strong></p>
<p>Use DESCRIBE to see which columns are in a table and what their datatypes          are:</p>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --></p>
<div id="textbox">
<div>
<pre class="large">SQL&gt; desc dept;
 Name                Null?    Type
 ------------------- -------- -----------------

 DEPTNO                       NUMBER(2)
 DNAME                        VARCHAR2(14)
 LOC                          VARCHAR2(13)</pre>
</div>
</div>
<p><!-- ccccccccccccccccccccccccccccccccccccccccccccccccc   --> <strong>Varchar tip </strong><br />
Oracle is case sensitive to data inside the tables,<br />
unlike column and table names which are usually upper case unless you          explicitly create them otherwise.</p>
<p>So, there is a difference between &#8216;SALES&#8217;, &#8216;sales&#8217; and even &#8216;Sales&#8217;.</p>
<p>If you are unsure of the case that is used in your data, you can force          the result to upper (or lower)<br />
case by calling the <em>upper</em> or <em>lower </em><a title="opens new window" href="http://www.oracle-database-tips.com/oracle_functions.html" target="_blank">function</a> to convert the column data, like this:</p>
<p>&#8230; where lower(dname) = &#8216;sales&#8217;;.</p>
<p><!-- ============================================================================================================================================================ --></p>
<h3>Recommended reading:</h3>
<p>Spend some time reading Oracle&#8217;s documentation to get comfortable with Oracle&#8217;s        syntax.</p>
<p>It will be worth the effort.</p>
<div id="content">
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fstatements_10002.htm%23i2065646&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fselect.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#i2065646" target="_blank">Oracle          Online Documentation: SQL Reference</a></li>
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Fqueries.htm%23i2068094&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Fselect.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries.htm#i2068094" target="_blank">Oracle Online Documentation : SQL Reference, SQL Queries and Subqueries</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/oracle-sql-select/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Background</title>
		<link>http://oracle-database-tips.com/wp/sql/sql-background</link>
		<comments>http://oracle-database-tips.com/wp/sql/sql-background#comments</comments>
		<pubDate>Fri, 23 Oct 2009 10:53:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[compliant databases]]></category>
		<category><![CDATA[data structure]]></category>
		<category><![CDATA[database engine]]></category>
		<category><![CDATA[horizontal rows]]></category>
		<category><![CDATA[oracle database]]></category>
		<category><![CDATA[rowid]]></category>
		<category><![CDATA[select statement]]></category>
		<category><![CDATA[sql background]]></category>
		<category><![CDATA[sql commands]]></category>
		<category><![CDATA[sql info]]></category>
		<category><![CDATA[surname data]]></category>
		<category><![CDATA[table cells]]></category>
		<category><![CDATA[vertical columns]]></category>

		<guid isPermaLink="false">http://oracle-database-tips.com/wp/?p=62</guid>
		<description><![CDATA[SQL is short for Structured Query Language.

It is the language you will use to access any data structure or its data in the Oracle database.
]]></description>
			<content:encoded><![CDATA[<p><strong>SQL </strong>is short for <strong>S</strong>tructured<strong> Q</strong>uery <strong>L</strong>anguage.</p>
<p>It is the language you will use to access any data structure or its data in the Oracle database.</p>
<p>You will use this to issue commands to send instructions to the database.</p>
<p>It is a standard across all compliant databases.</p>
<p>SQL commands work on sets of data and allow you to :</p>
<ul>
<li>Query the data (select)</li>
<li>Change the data (insert, update, delete)</li>
<li>Work with data structures (create or replace, alter, drop)</li>
<li>Determine access rules to data and structures (grant)</li>
<li>Lock rows or tables to enforce consistency. (lock)</li>
</ul>
<h3>Tables and indexes</h3>
<p>A<strong> table </strong> is a structure which contains horizontal rows and vertical columns.</p>
<p>The intersection of a row and a column is a cell.</p>
<p>When we search for data in a table, we use the SQL &#8216;select&#8217; statement          to extract the data in the table cells by specifying which &#8216;intersection&#8217;          of column  and row we want to extract results for. (More details later..)</p>
<table border="1" cellspacing="0" cellpadding="0" width="405">
<tbody>
<tr>
<td width="81"></td>
<td width="161">Column A</td>
<td width="155">Column B</td>
</tr>
<tr>
<td>Row 1</td>
<td>Cell: column A, row 1</td>
<td>Cell: column B, row 1</td>
</tr>
<tr>
<td>Row 2</td>
<td>Cell: column A, row 2</td>
<td>Cell: column B, row 2</td>
</tr>
</tbody>
</table>
<p>Here&#8217;s a real-world example of a table:</p>
<p>Table: Employees, contains 3 columns : EmployeeID, Surname and Firstname          and 4 rows of data.<br />
Each table has a hidden column called rowid which uniquely identifies          each row in the table.</p>
<table border="1" cellspacing="0" cellpadding="0" width="524">
<tbody>
<tr>
<td width="224">Rowid</td>
<td width="113"><strong>EmployeeID</strong></td>
<td width="61"><strong>Surname</strong></td>
<td width="116"><strong>Firstname</strong></td>
</tr>
<tr>
<td>AAAUM2AAMAACepMAAA</td>
<td>J001</td>
<td>Jones</td>
<td>Abe</td>
</tr>
<tr>
<td>AAAUM2AAMAACepMAAB</td>
<td>S001</td>
<td>Smith</td>
<td>Brian</td>
</tr>
<tr>
<td>AAAUM2AAMAACepMAAB</td>
<td>B001</td>
<td>Beckett</td>
<td>Chris</td>
</tr>
<tr>
<td>AAAUM2AAMAACepMAAD</td>
<td>B002</td>
<td>Brown</td>
<td>David</td>
</tr>
</tbody>
</table>
<p><strong>Index:</strong> a technique implemented by the database engine          to conduct data access as fast as possible.</p>
<p>An index on the &#8216;Surname&#8217; column of the Employees table would create          another &#8216;table&#8217; (but now called an index) containing only the sorted Surname data and the rowid of that row.</p>
<p>When you query data in the Surname column of the Employees table,<br />
the database engine&#8217;s optimizer determines whether or not to use the index,<br />
based on the expected number of rows it has to return.<br />
If it detects and uses the relevant index, it does a search on the index rather than the table.</p>
<p>Once if finds the correct row, it uses the stored rowid to access the          Employees table directly (no searching) to retrieve the whole row.</p>
<p>Once an index is created, you do not need to maintain it, nor do you need to use its name to access<br />
the data in the table. The Oracle engine does that for you in the background.</p>
<h3>Normalization:</h3>
<p>A methodology to design a database system in such a way so that there is no or limited data duplication.<br />
No table should contain data already stored in another table unless it is a link to a row<br />
in the other table (foreign key relationships).<br />
There are many other rules and degrees of normalization , if you would<br />
like to read more about it , see the link below in &#8216;Additional resources&#8217;.</p>
<h3>Recommended reading:</h3>
<p>For more info on relational database theory, here&#8217;s an excellent well-priced resource:</p>
<div id="content">
<li><a title="opens new window" href="http://www.oracle-database-tips.com/alflink" target="_blank">Database Normalization ebook by Alf Pedersen</a></li>
<p>If you have time to scan through Oracle&#8217;s manual about SQL, follow the link to the online documentation :</p>
<li><a title="opens new window" onclick="window.open('http://www.oracle-database-tips.com/cgi-bin/counter.pl?url=http%3A%2F%2Fdownload.oracle.com%2Fdocs%2Fcd%2FB19306_01%2Fserver.102%2Fb14200%2Ftoc.htm&amp;referrer=http%3A%2F%2Fwww.oracle-database-tips.com%2Foracle_sql_background.html'); return false;" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm" target="_blank">Oracle SQL Background reference (Oracle online documentation)</a></li>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oracle-database-tips.com/wp/sql/sql-background/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

