<?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; function syntax</title>
	<atom:link href="http://oracle-database-tips.com/wp/tag/function-syntax/feed" rel="self" type="application/rss+xml" />
	<link>http://oracle-database-tips.com/wp</link>
	<description>News for Oracle professionals</description>
	<lastBuildDate>Fri, 11 May 2012 12:12:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Oracle 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>
	</channel>
</rss>

