<?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>SQL and PLSQL &#187; Functions</title>
	<atom:link href="http://plsql.globinch.com/category/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://plsql.globinch.com</link>
	<description>SQL and PLSQL Technology Tips</description>
	<lastBuildDate>Thu, 07 Apr 2011 17:04:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Oracle CURSOR with parameter</title>
		<link>http://plsql.globinch.com/2009/02/02/oracle-cursor-with-parameter/</link>
		<comments>http://plsql.globinch.com/2009/02/02/oracle-cursor-with-parameter/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 13:02:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Cursors]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Fundamentals]]></category>
		<category><![CDATA[Key Words]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[CLOSE cursor]]></category>
		<category><![CDATA[Cursor]]></category>
		<category><![CDATA[Fetch cursor]]></category>
		<category><![CDATA[open cursor]]></category>
		<category><![CDATA[Oracle cursor]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=77</guid>
		<description><![CDATA[Oracle CURSOR with parameter.Execution of a cursor puts the results of the query into a set of rows called the result set, which can be fetched sequentially or non sequentially.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "Oracle CURSOR with parameter";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2009/02/02/oracle-cursor-with-parameter/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F02%2F02%2Foracle-cursor-with-parameter%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F02%2F02%2Foracle-cursor-with-parameter%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Execution of a <a href="http://plsql.globinch.com/2009/02/02/cursor-oracle-plsql-cursors-and-example/" target="_self">cursor </a>puts the results of the query into a set of rows called the result set, which can be fetched sequentially or non sequentially.<br />
You can create <a href="http://plsql.globinch.com/2009/02/02/cursor-oracle-plsql-cursors-and-example/" target="_self">Cursors </a>which accepts parameters at runtime.</p>
<p><span style="font-style: italic; font-weight: bold; color: #cc0000;">Read:</span><a href="http://plsql.globinch.com/2009/02/02/cursor-oracle-plsql-cursors-and-example/">Cursor | Oracle PL/SQL Cursors and example.</a><br />
<span style="font-style: italic; font-weight: bold; color: #cc0000;">Read:</span><a href="http://plsql.globinch.com/2009/02/02/ora-01000-maximum-open-cursors-exceeded/" target="_self">ORA-01000: maximum open cursors exceeded.</a><br />
<span style="font-style: italic; font-weight: bold; color: #cc0000;">Read:</span><a href="http://plsql.globinch.com/2009/02/02/oracle-cursors-open-fetch-and-close-cursor-statements/" target="_self">Oracle Cursors | OPEN ,FETCH and CLOSE Cursor statements.</a><br />
<span style="font-style: italic; font-weight: bold; color: #cc0000;">Read:</span><a href="http://plsql.globinch.com/2009/02/02/ora-01001-invalid-cursor/" target="_self">ORA-01001: invalid cursor</a></p>
<p>Example:</p>
<p><span style="font-weight: bold;">Step 1:</span></p>
<pre class="brush: css;">create table PERSON( PERSON_ID NUMBER(19) not null, AGE       NUMBER(10), FIRSTNAME VARCHAR2(255), LASTNAME  VARCHAR2(255));

SQL&amp;gt; insert into Person values(1,10,'Geek','Greek');

1 row inserted

SQL&amp;gt; insert into Person values(2,12,'Seek','Bells');

1 row inserted

SQL&amp;gt; insert into Person values(3,13,'Creek','Dells');

1 row inserted

SQL&amp;gt;SQL&amp;gt; insert into Person values(4,13,'Sreek','Sells');

1 row inserted

SQL&amp;gt;</pre>
<p><span style="font-weight: bold;">Step 2:</span></p>
<p>Now write a small procedure to illustrate the cursor which accepts a parameter at run time.</p>
<pre class="brush: css;">create or replace procedure Param_Cursor as

CURSOR PERSON_CUR(pAge NUMBER) isSelect * from Person p where p.age = pAge;

BEGIN    for i in PERSON_CUR(13) loop       dbms_output.put_line(i.firstname);    end loop;

END Param_Cursor;</pre>
<p><span style="font-weight: bold;">Step3:</span></p>
<p>Now run the procedure Param_Cursor.</p>
<pre class="brush: css;">SQL&amp;gt; set serveroutput on;SQL&amp;gt; exec Param_Cursor;CreekSreek

PL/SQL procedure successfully completed

SQL&amp;gt;</pre>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for Cursor" rel="tag" href="http://www.technorati.com/tag/Cursor" target="_blank">Cursor</a>, <a title="Link to Technorati Tag category for CLOSE cursor" rel="tag" href="http://www.technorati.com/tag/CLOSE+cursor" target="_blank">CLOSE cursor</a>, <a title="Link to Technorati Tag category for open cursor" rel="tag" href="http://www.technorati.com/tag/open+cursor" target="_blank">open cursor</a>, <a title="Link to Technorati Tag category for Fetch cursor" rel="tag" href="http://www.technorati.com/tag/Fetch+cursor" target="_blank">Fetch cursor</a>, <a title="Link to Technorati Tag category for Oracle cursor" rel="tag" href="http://www.technorati.com/tag/Oracle+cursor" target="_blank">Oracle cursor</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2009/02/02/oracle-cursor-with-parameter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle: SQL MIN Function &#124; MIN() function in SQL</title>
		<link>http://plsql.globinch.com/2009/01/09/oracle-sql-min-function-min-function-in-sql/</link>
		<comments>http://plsql.globinch.com/2009/01/09/oracle-sql-min-function-min-function-in-sql/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 10:24:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Key Words]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=58</guid>
		<description><![CDATA[The MIN function returns the minimum value of an expression.MIN() function is reverse of MAX() function.MIN() function can be used along with GROUP BY clause also.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "Oracle: SQL MIN Function | MIN() function in SQL";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2009/01/09/oracle-sql-min-function-min-function-in-sql/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F01%2F09%2Foracle-sql-min-function-min-function-in-sql%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F01%2F09%2Foracle-sql-min-function-min-function-in-sql%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<div style="text-align: left;">The <span style="font-weight: bold; color: #cc0000;">MIN </span>function returns the minimum value of an expression.<span style="font-weight: bold;">MIN() </span>function is reverse of <a href="http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/">MAX() function</a>.<span style="font-weight: bold;">MIN() function </span>can be used along with <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a> clause also.</div>
<p><span style="font-weight: bold;">SYNTAX:</span></p>
<pre class="brush: css;">
SELECT MIN(expression ) FROM tables WHERE (condition);
</pre>
<p>The example given below explains the usage of <span style="font-weight: bold;">MIN() </span>function and usage of MIN along with <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a> clause.</p>
<pre class="brush: css;">
SQL&gt; create table MYTABLE (name varchar2(50),age number,department varchar2(20));
Table created

SQL&gt; insert into MYTABLE values ('AAA',12,'D1');
SQL&gt; insert into MYTABLE values ('BBB',42,'D2');
SQL&gt; insert into MYTABLE values ('CCC',22,'D2');
SQL&gt; insert into MYTABLE values ('DDD',32,'D1');

4 row inserted

SQL&gt; select min(age) from MYTABLE;
MIN(AGE)
12

SQL&gt; select min(age) from MYTABLE where age &gt;20;
MIN(AGE)
22
</pre>
<p><span style="color: #000000; font-weight: bold;">Usage of MIN() function with <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a></span></p>
<pre class="brush: css;">
SQL&gt; select department ,min(age) from MYTABLE group by department;

DEPARTMENT MIN(AGE)
D1    12&lt;
D2    22
</pre>
<p><span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-style: normal; font-variant: normal; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033; font-family: arial,helvetica,sans-serif; font-size: 13px;">Related Articles,</span></p>
<ul id="Feed2_feedItemListDisplay">
<li><a href="../2009/01/05/sql-min-function-min-function-in-sql/">SQL MIN Function | MIN() function in SQL</a></li>
<li><a href="../2008/12/17/sql-count-function-usage-of-count-and-count1/">SQL COUNT() Function ,Usage of COUNT(*) and COUNT(1)</a></li>
<li><a href="../2008/12/17/sql-order-by-using-order-by-clause-in-sql/">SQL order by ,using ‘ORDER BY’ clause in SQL</a></li>
<li><a href="../2008/12/04/oracle-maxdate-sql-max-date/">Oracle Max(Date)? | sql max date</a></li>
<li><a href="../2008/12/04/oracle-trim-function-plsql-trim-function/">Oracle Trim Function | PL/SQL TRIM Function.</a></li>
<li><a href="../2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values</a></li>
<li><a href="../2008/12/03/sql-max-function-sql-max-examples/">SQL: MAX Function | SQL Max examples</a></li>
<li><a href="../2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">SQL GROUP BY Statement | SQL GROUP BY Clause examples</a></li>
<li><a href="../2008/12/01/nvl-oracleplsql-nvl-function/">NVL | Oracle/PLSQL: NVL Function</a></li>
</ul>
<p style="font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for SQL MIN" rel="tag" href="http://www.technorati.com/tag/SQL+MIN" target="_blank">SQL MIN</a>, <a title="Link to Technorati Tag category for MIN function" rel="tag" href="http://www.technorati.com/tag/MIN+function" target="_blank">MIN function</a>, <a title="Link to Technorati Tag category for MIN() function" rel="tag" href="http://www.technorati.com/tag/MIN%28%29+function" target="_blank">MIN() function</a>, <a title="Link to Technorati Tag category for GROUP BY" rel="tag" href="http://www.technorati.com/tag/GROUP+BY" target="_blank">GROUP BY</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2009/01/09/oracle-sql-min-function-min-function-in-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>COUNT() Function in SQL ,Using COUNT(*) and COUNT(1)</title>
		<link>http://plsql.globinch.com/2009/01/09/count-function-in-sql-using-count-and-count1/</link>
		<comments>http://plsql.globinch.com/2009/01/09/count-function-in-sql-using-count-and-count1/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 10:18:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Key Words]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=56</guid>
		<description><![CDATA[The COUNT() function returns the number of records in a tables based on sql query.
The COUNT function will only count those records in which the field in the brackets is NOT NULL.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "COUNT() Function in SQL ,Using COUNT(*) and COUNT(1)";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2009/01/09/count-function-in-sql-using-count-and-count1/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F01%2F09%2Fcount-function-in-sql-using-count-and-count1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F01%2F09%2Fcount-function-in-sql-using-count-and-count1%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The <span style="font-weight: bold; color: #ff0000;">COUNT() </span>function returns the number of records in a tables based on <span style="font-weight: bold;">sql </span>query.<br />
The <span style="font-weight: bold;">COUNT </span>function will only count those records in which the field in the brackets is <span style="font-weight: bold;">NOT NULL.</span></p>
<p><span style="font-weight: bold;">SYNTAX:</span></p>
<pre class="brush: css;">
SELECT COUNT(expression)
FROM tables
WHERE predicates;
</pre>
<p><span style="font-weight: bold;">EXAMPLE:</span><br />
<span style="font-weight: bold;">STEP 1</span>:Create the following table,&#8217;MYTABLE&#8217; and insert few records.</p>
<pre class="brush: css;">
SQL&gt;  create table MYTABLE (NAME varchar2(50), Age number,id number);
SQL&gt; Table created
SQL&gt; insert into MYTABLE values('BBB',12,1);
SQL&gt; insert into MYTABLE values('DDD',22,2);
SQL&gt; insert into MYTABLE values('CCC',32,3);
SQL&gt; insert into MYTABLE values('AAA',62,4);
SQL&gt; insert into MYTABLE values('CCC',42,5);
SQL&gt;5 rows inserted
</pre>
<p><span style="font-weight: bold;">STEP 2:</span>Now run the following query.</p>
<pre class="brush: css;">
SQL&gt;  select count(*) from MYTABLE;

COUNT(*)
   5
</pre>
<p><span style="font-weight: bold;">COUNT </span>function will return the same results regardless of what NOT NULL field(s) you include as the COUNT function parameters<br />
If you use <span style="font-weight: bold; color: #ff0000;">COUNT(*)</span> the query will retrieve all fields from the table inorder to calculate count,To avoid this we can use <span style="font-weight: bold; color: #ff0000;">COUNT(1)</span> instead of COUNT(*).It will merely retrieve the numeric value of 1 for each record that meets your criteria.This can be used as a performance tip.</p>
<p>It is possible to use <span style="font-weight: bold;">DISTINCT </span>clause within the <span style="font-weight: bold;">COUNT </span>function to give exact count omitting duplicates.</p>
<pre class="brush: css;">
SQL&gt; select count(distinct name) names from mytable;
NAMES
  4
SQL&gt;
</pre>
<p>You can also use<span style="font-weight: bold;"> <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a></span> function along with COUNT( Check <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY Here</a>).<br />
This is required when you need a combination of coulmns and number of records in a result set.Because you have listed one column in your SELECT statement that is not encapsulated in the COUNT function, you must use a GROUP BY clause.</p>
<p><span style="font-weight: bold;">EXAMPLE: </span>The following query will give you name and number of occurances from MYTABLE.</p>
<pre class="brush: css;">
SQL&gt;  select name ,COUNT( NAME) from MYTABLE GROUP BY name;

NAME                                               COUNT(NAME)
BBB                                                       1
CCC                                                       2
AAA                                                       1
DDD                                                       1

SQL&gt;
</pre>
<p><span style="font-weight: bold;">EXAMPLE: </span>The following query will return people with age&lt;40</p>
<pre class="brush: css;">
SQL&gt; select name ,count(*)NUMBER_OF_PEOPLE from mytable where age&lt;40;
NAME                                               NUMBER_OF_PEOPLE
BBB                                                 1
CCC                                                 1
DDD                                                 1

SQL&gt;
</pre>
<p><span style="font-weight: bold;">EXAMPLE: </span>The following query will return people with age&gt;30</p>
<pre class="brush: css;">
SQL&gt; select name ,count(*)NUMBER_OF_PEOPLE from mytable where age &gt;30 group by name;
NAME                                               NUMBER_OF_PEOPLE
CCC                                                           2
AAA                                                           1
SQL&gt;
</pre>
<p><span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-family: arial,helvetica,sans-serif; font-style: normal; font-variant: normal; font-size: 13px; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033;">Related Articles,</span></p>
<ul id="Feed2_feedItemListDisplay">
<li><a href="http://plsql.globinch.com/2009/01/05/sql-min-function-min-function-in-sql/">SQL MIN Function | MIN() function in SQL</a></li>
<li><a href="http://plsql.globinch.com/2008/12/17/sql-count-function-usage-of-count-and-count1/">SQL COUNT() Function ,Usage of COUNT(*) and COUNT(1)</a></li>
<li><a href="http://plsql.globinch.com/2008/12/17/sql-order-by-using-order-by-clause-in-sql/">SQL order by ,using ‘ORDER BY’ clause in SQL</a></li>
<li><a href="http://plsql.globinch.com/2008/12/04/oracle-maxdate-sql-max-date/">Oracle Max(Date)? | sql max date</a></li>
<li><a href="http://plsql.globinch.com/2008/12/04/oracle-trim-function-plsql-trim-function/">Oracle Trim Function | PL/SQL TRIM Function.</a></li>
<li><a href="http://plsql.globinch.com/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values</a></li>
<li><a href="http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/">SQL: MAX Function | SQL Max examples</a></li>
<li><a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">SQL GROUP BY Statement | SQL GROUP BY Clause examples</a></li>
<li><a href="http://plsql.globinch.com/2008/12/01/nvl-oracleplsql-nvl-function/">NVL | Oracle/PLSQL: NVL Function</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for SQL COUNT() Function" rel="tag" href="http://www.technorati.com/tag/SQL+COUNT%28%29+Function" target="_blank">SQL COUNT() Function</a>, <a title="Link to Technorati Tag category for COUNT(*)" rel="tag" href="http://www.technorati.com/tag/COUNT%28*%29" target="_blank">COUNT(*)</a>, <a title="Link to Technorati Tag category for COUNT(1)" rel="tag" href="http://www.technorati.com/tag/COUNT%281%29" target="_blank">COUNT(1)</a>, <a title="Link to Technorati Tag category for SQL COUNT" rel="tag" href="http://www.technorati.com/tag/SQL+COUNT" target="_blank">SQL COUNT</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2009/01/09/count-function-in-sql-using-count-and-count1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8216;ORDER BY&#8217; clause in SQL &#124; Using SQL order by</title>
		<link>http://plsql.globinch.com/2009/01/09/order-by-clause-in-sql-using-sql-order-by/</link>
		<comments>http://plsql.globinch.com/2009/01/09/order-by-clause-in-sql-using-sql-order-by/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 10:15:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Key Words]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=55</guid>
		<description><![CDATA[The keyword 'ORDER BY' clause used in SQL to order the data sets retrieved from a SQL database.
The sorting of result set can be based on column or columns.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "&#8216;ORDER BY&#8217; clause in SQL | Using SQL order by";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2009/01/09/order-by-clause-in-sql-using-sql-order-by/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F01%2F09%2Forder-by-clause-in-sql-using-sql-order-by%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2009%2F01%2F09%2Forder-by-clause-in-sql-using-sql-order-by%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The keyword &#8216;<span style="font-weight: bold; color: #ff0000;">ORDER BY</span>&#8216; clause used in <span style="font-weight: bold;">SQL </span>to order the data sets retrieved from a <span style="font-weight: bold;">SQL</span> database.<br />
The sorting of result set can be based on column or columns.</p>
<p><span style="font-weight: bold;">Example:</span><br />
<span style="font-weight: bold;">Step:1:</span> Create the table as follows:</p>
<pre class="brush: css;">
SQL&gt;  create table MYTABLE (NAME varchar2(50), Age number,id number);&lt;
Table created
SQL&gt;
</pre>
<p><span style="font-weight: bold;">STEP:2:</span> Insert few records into &#8216;MYTABLE&#8217;.</p>
<pre class="brush: css;">
SQL&gt; insert into MYTABLE values('BBB',22,1);
SQL&gt; insert into MYTABLE values('DDD',22,2);
SQL&gt; insert into MYTABLE values('CCC',22,3);
SQL&gt; insert into MYTABLE values('AAA',22,4);
SQL&gt; insert into MYTABLE values('EEE',22,5);
</pre>
<p><span style="font-weight: bold;">STEP:3: </span>Run a normal query to retrieve the result set.</p>
<pre class="brush: css;">
SQL&gt;  select * from MYTABLE;
NAME                                                     AGE         ID
BBB                                                        22          1&lt;
DDD                                                        22          2
CCC                                                        22          3
AAA                                                        22          4
EEE                                                        22          5
</pre>
<p><span style="font-weight: bold;">STEP:4</span>: Now use the &#8216;<span style="font-weight: bold;">ORDER BY</span>&#8216; keyword in the query and use &#8216;NAME&#8217; column to sort.</p>
<pre class="brush: css;">
SQL&gt;  select * from MYTABLE order by name;
NAME                                                      AGE         ID
AAA                                                        22          4
BBB                                                        22          1
CCC                                                        22          3
DDD                                                        22          2
EEE                                                        22          5
</pre>
<p>By defaults the &#8216;<span style="font-weight: bold;">ORDER BY</span>&#8216; query returns natural ordered results.Otherwise you need to use &#8216;<span style="font-weight: bold; color: #ff0000;">ASC</span>&#8216; or &#8216;<span style="font-weight: bold; color: #ff0000;">DESC</span>&#8216; keywords.<br />
<span style="font-weight: bold;">ORDER BY </span>clause usually followed by &#8216;<span style="font-weight: bold;">ASC</span>&#8216; or &#8216;<span style="font-weight: bold;">DESC</span>&#8216; keywords in order to indicate the sorting order either by &#8216;ascending&#8217; or &#8216;descending&#8217;.<br />
<span style="font-weight: bold;">ASC </span>keyword orders the result set by the specified columns alphabetically. <span style="font-weight: bold;">DESC </span>sort the result set backwards ,i.e just opposite of &#8216;ASC&#8217;</p>
<p><span style="font-weight: bold;">STEP:5: </span>Use the &#8216;<span style="font-weight: bold;">DESC</span>&#8216; keyword in the query mentioned in STEP:4</p>
<pre class="brush: css;">
SQL&gt; select * from MYTABLE order by name DESC;
NAME                                                      AGE         ID
EEE                                                        22          5
DDD                                                        22          2
CCC                                                        22          3
BBB                                                        22          1
AAA                                                        22          4
</pre>
<p>You can sort your result set by more than one column by specifying those columns in the <span style="font-weight: bold;">SQL ORDER BY</span> list.When using <span style="font-weight: bold;">ORDER BY</span> with more than one column, you need to separate the columns following <span style="font-weight: bold;">ORDER BY </span>with commas.<br />
If you need specific ordering based on more than one column, you need to specify <span style="font-weight: bold;">ASC</span> and/or <span style="font-weight: bold;">DESC </span>after each column.</p>
<p><span style="font-weight: bold;">STEP:6:</span> Example of using multiple columns in &#8216;ORDER BY&#8217; clause.</p>
<pre class="brush: css;">
SQL&gt;  select * from MYTABLE order by name ASC,ID DESC;
NAME                                                      AGE         ID
AAA                                                        22          4
BBB                                                        22          1
CCC                                                        22          3
DDD                                                        22          2
EEE                                                        22          5
</pre>
<p><span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-style: normal; font-variant: normal; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033; font-family: arial,helvetica,sans-serif; font-size: 13px;">Related Articles,</span></p>
<ul id="Feed2_feedItemListDisplay">
<li><a href="../2009/01/05/sql-min-function-min-function-in-sql/">SQL MIN Function | MIN() function in SQL</a></li>
<li><a href="../2008/12/17/sql-count-function-usage-of-count-and-count1/">SQL COUNT() Function ,Usage of COUNT(*) and COUNT(1)</a></li>
<li><a href="../2008/12/04/oracle-maxdate-sql-max-date/">Oracle Max(Date)? | sql max date</a></li>
<li><a href="../2008/12/04/oracle-trim-function-plsql-trim-function/">Oracle Trim Function | PL/SQL TRIM Function.</a></li>
<li><a href="../2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values</a></li>
<li><a href="../2008/12/03/sql-max-function-sql-max-examples/">SQL: MAX Function | SQL Max examples</a></li>
<li><a href="../2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">SQL GROUP BY Statement | SQL GROUP BY Clause examples</a></li>
<li><a href="../2008/12/01/nvl-oracleplsql-nvl-function/">NVL | Oracle/PLSQL: NVL Function</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for ORDER BY" rel="tag" href="http://www.technorati.com/tag/ORDER+BY" target="_blank">ORDER BY</a>, <a title="Link to Technorati Tag category for SQL ORDER BY" rel="tag" href="http://www.technorati.com/tag/SQL+ORDER+BY" target="_blank">SQL ORDER BY</a>, <a title="Link to Technorati Tag category for SQL Keywords" rel="tag" href="http://www.technorati.com/tag/SQL+Keywords" target="_blank">SQL Keywords</a>, <a title="Link to Technorati Tag category for ASC" rel="tag" href="http://www.technorati.com/tag/ASC" target="_blank">ASC</a>, <a title="Link to Technorati Tag category for DESC" rel="tag" href="http://www.technorati.com/tag/DESC" target="_blank">DESC</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2009/01/09/order-by-clause-in-sql-using-sql-order-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Max(Date) function usage-SQL max date</title>
		<link>http://plsql.globinch.com/2008/12/04/oracle-maxdate-sql-max-date/</link>
		<comments>http://plsql.globinch.com/2008/12/04/oracle-maxdate-sql-max-date/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 12:31:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=38</guid>
		<description><![CDATA[Max() function in sql can be used to get maximum value of two or more dates.Max(Date) function is useful in retrieving the maximum value of date from a record set or column or result set etc.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "Oracle Max(Date) function usage-SQL max date";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/12/04/oracle-maxdate-sql-max-date/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F04%2Foracle-maxdate-sql-max-date%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F04%2Foracle-maxdate-sql-max-date%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><span style="color: #000000;"><a href="http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/"><strong>Max()</strong> function</a> </span><span style="color: #3333ff;"><span style="color: #000000;">in sql can be used to get maximum value of two or more dates.</span></span><span style="font-style: italic; color: #3333ff; font-weight: bold;"><span style="color: #000000;">M</span></span><span style="font-weight: bold;">ax(Date)</span> function is useful in retrieving the maximum value of date from a record set or column or result set etc.The  following examples shows the usage of <a href="http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/">Max()</a> function to find out maximum value of dates.</p>
<p><span style="font-style: italic; color: #3333ff;">Read more about</span> SQL MAX() function <a href="http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/">here</a>.<br />
<span style="font-style: italic; color: #3333ff;">Read more about oracle DATE here </span>&gt;&gt; <span style="font-size: 85%;"><a href="http://plsql.globinch.com/2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/">DATE Data type</a>,<span style="font-size: 85%;"><a href="http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/">TO_DATE </a>,<a href="http://plsql.globinch.com/2008/11/19/oracle-to_char-function-and-usage/">TO_CHAR</a> ,<a href="http://plsql.globinch.com/2008/11/20/oracle-plsql-to_timestamp-function-datetime-format-models/">TO_TIMESTAMP</a></span>,<a href="http://plsqlworld.blogspot.com/2008/11/oracle-timestamp-format-oracle-date.html">timestamp format</a>,<a href="http://plsql.globinch.com/2008/11/20/oracle-date-vs-timestamp-comparing-oracle-date-and-timestamp-datatypes/">DATE vs TIMESTAMP</a> ,<a href="http://plsql.globinch.com/2008/11/19/oracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql/">comparing dates</a>,<a href="http://plsql.globinch.com/2008/11/19/using-oracle-date-format-using-the-date-format-mask-in-plsql/">DATE Format</a></span></p>
<p><span style="font-weight: bold; color: #990000;">Example for Max(date):</span></p>
<p><span style="font-weight: bold;">Step 1:</span> Create table DATETABLE as follows ,which is having a DATE column as &#8216;thedate&#8217;.</p>
<pre class="brush: css;">
SQL&gt;  create table DateTable (id number, thedate date);
Table created
</pre>
<p><span style="font-weight: bold;">STEP 2:</span> Insert the following records in DATETABLE.</p>
<pre class="brush: css;">
SQL&gt; insert into dateTable values(1, sysdate-1);
SQL&gt; insert into dateTable values(2, sysdate);
SQL&gt; insert into dateTable values(3, sysdate+1);
SQL&gt; insert into dateTable values(4, sysdate+2);

4 row inserted
</pre>
<p><span style="font-weight: bold;">STEP 3: </span>Query the table for Id of the row which is having the maximum value of &#8216;thedate&#8217;.</p>
<pre class="brush: css;">
SQL&gt;  select id from datetable where thedate =(select max(thedate) from datetable);
ID
4
</pre>
<p><span style="font-style: italic; color: #3333ff;">Read more about</span> <a href="http://plsqlworld.blogspot.com/2008/12/sql-max-function-sql-max-examples.html">SQL MAX() </a>function <a href="http://plsqlworld.blogspot.com/2008/12/sql-max-function-sql-max-examples.html">here</a>.<br />
<span style="font-style: italic; color: #3333ff;">Read more about oracle DATE here </span>&gt;&gt; <span style="font-size: 85%;"><a href="http://plsqlworld.blogspot.com/2008/11/date-data-type-in-oracleoracle-dates.html">DATE Data type</a>,<span style="font-size: 85%;"><a href="http://plsqlworld.blogspot.com/2008/11/oracle-todate-oracleplsql-todate.html">TO_DATE</a> ,<a href="http://plsqlworld.blogspot.com/2008/11/oracle-tochar-function-and-usage.html">TO_CHAR</a> ,<a href="http://plsqlworld.blogspot.com/2008/11/oracle-plsql-totimestamp-function.html">TO_TIMESTAMP</a></span>,<a href="http://plsqlworld.blogspot.com/2008/11/oracle-timestamp-format-oracle-date.html">timestamp format</a>,<a href="http://plsqlworld.blogspot.com/2008/11/oracle-date-vs-timestamp-comparing.html">DATE vs TIMESTAMP</a> ,<a href="http://plsqlworld.blogspot.com/2008/11/oracle-comparing-dates-dates-oracle.html">comparing dates</a>,<a href="http://plsqlworld.blogspot.com/2008/11/using-oracle-date-format-using-date.html">DATE Format</a></span></p>
<p><span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-family: arial,helvetica,sans-serif; font-style: normal; font-variant: normal; font-size: 13px; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033;">Related Articles,</span></p>
<ul>
<li> <a title="Permalink to Oracle DATE vs TIMESTAMP |Comparing Oracle DATE and TIMESTAMP Datatypes" rel="bookmark" href="../2008/11/20/oracle-date-vs-timestamp-comparing-oracle-date-and-timestamp-datatypes/">Oracle PL/SQL: To_Timestamp Function | Datetime Format ModelsOracle DATE vs TIMESTAMP |Comparing Oracle DATE and TIMESTAMP Datatypes</a></li>
<li> <a title="Permalink to Oracle to_char function and usage" rel="bookmark" href="../2008/11/19/oracle-to_char-function-and-usage/">Oracle to_char function and usage</a></li>
<li><a title="Permalink to Using oracle date format |Using the DATE Format Mask in pl/sql" rel="bookmark" href="../2008/11/19/using-oracle-date-format-using-the-date-format-mask-in-plsql/">Using oracle date format |Using the DATE Format Mask in pl/sql</a></li>
<li><a title="Permalink to Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql" rel="bookmark" href="../2008/11/19/oracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql/">Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql</a></li>
<li> <a title="Permalink to ORA-01882: TIMEZONE REGION NOT FOUND |Oracle Error" rel="bookmark" href="../2008/11/18/ora-01882-timezone-region-not-found-oracle-error/">ORA-01882: TIMEZONE REGION NOT FOUND |Oracle Error</a></li>
<li> <a title="Permalink to PL/SQL EXTRACT function for oracle datetime" rel="bookmark" href="../2008/11/18/plsql-extract-function-for-oracle-datetime/">PL/SQL EXTRACT function for oracle datetime</a></li>
<li> <a title="Permalink to Oracle Dates and Times |SYSDATE|CURRENT_TIMESTAMP |SYSTIMESTAMP |DBTIMEZONE |LOCALTIMESTAMP" rel="bookmark" href="../2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/">Oracle Dates and Times |SYSDATE|CURRENT_TIMESTAMP |SYSTIMESTAMP |DBTIMEZONE |LOCALTIMESTAMP</a></li>
<li> <a title="Permalink to oracle to_date | Oracle/PLSQL: To_Date Function" rel="bookmark" href="../2008/11/18/oracle-to_date-oracleplsql-to_date-function/">oracle to_date | Oracle/PLSQL: To_Date Function</a></li>
</ul>
<p style="text-align: right; font-size: 9px; display: none;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for SQL MAX() function" rel="tag" href="http://www.technorati.com/tag/SQL+MAX%28%29+function" target="_blank">SQL MAX() function</a>, <a title="Link to Technorati Tag category for SQL MAX" rel="tag" href="http://www.technorati.com/tag/SQL+MAX" target="_blank">SQL MAX</a>, <a title="Link to Technorati Tag category for Oracle MAX" rel="tag" href="http://www.technorati.com/tag/Oracle+MAX" target="_blank">Oracle MAX</a>, <a title="Link to Technorati Tag category for Max(date)" rel="tag" href="http://www.technorati.com/tag/Max%28date%29" target="_blank">Max(date)</a>, <a title="Link to Technorati Tag category for DATE" rel="tag" href="http://www.technorati.com/tag/DATE" target="_blank">DATE</a>, <a title="Link to Technorati Tag category for DATE Data type" rel="tag" href="http://www.technorati.com/tag/DATE+Data+type" target="_blank">DATE Data type</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/12/04/oracle-maxdate-sql-max-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Trim Function &#124; PL/SQL TRIM() Function.</title>
		<link>http://plsql.globinch.com/2008/12/04/oracle-trim-function-plsql-trim-function/</link>
		<comments>http://plsql.globinch.com/2008/12/04/oracle-trim-function-plsql-trim-function/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 11:15:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=37</guid>
		<description><![CDATA[TRIM function removes all specified characters from the beginning of a string or from the ending of a string.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "Oracle Trim Function | PL/SQL TRIM() Function.";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/12/04/oracle-trim-function-plsql-trim-function/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F04%2Foracle-trim-function-plsql-trim-function%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F04%2Foracle-trim-function-plsql-trim-function%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><span style="font-style: italic; color: #6633ff; font-weight: bold;">See Other related SQL and PLSQL Functions : </span><br />
&gt;&gt;&gt; <span style="font-size: 85%;"><a href="http://plsql.globinch.com/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">DECODE </a>,<a href="http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/">MAX </a>,<a href="http://plsql.globinch.com/2008/12/01/nvl-oracleplsql-nvl-function/">NVL </a>,<a href="http://plsql.globinch.com/2008/12/01/oracleplsql-instr-function-instr-functions-case-sensitive-search/">INSTR </a>,<a href="http://plsqlworld.blogspot.com/2008/11/substr-functions-oracleplsql-substr.html">SUBSTR </a>,<a href="http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/">TO_DATE</a> ,<a href="http://plsql.globinch.com/2008/11/19/oracle-to_char-function-and-usage/">TO_CHAR</a> ,<a href="http://plsql.globinch.com/2008/11/20/oracle-plsql-to_timestamp-function-datetime-format-models/">TO_TIMESTAMP</a> ,<a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a></span>,<a href="http://plsql.globinch.com/2008/11/18/plsql-extract-function-for-oracle-datetime/">Extract</a></p>
<p><span style="font-weight: bold; color: #009900;">TRIM</span> function removes all specified characters from the beginning of a string or from the ending of a string.<span class="fullpost"> </span></p>
<p><span style="font-weight: bold;">Syntax:</span></p>
<pre class="brush: css;">
trim( [ leading or trailing or both  , trim_string ,   stringToTrim )
</pre>
<p><span style="font-weight: bold;">leading -</span> This removes the &#8216;<span style="font-style: italic;">trim_string</span>&#8216; from the beginning of &#8216;<span style="font-style: italic;">stringToTrim</span>&#8216;.<br />
<span style="font-weight: bold;">trailing -</span>This removes the &#8216;<span style="font-style: italic;">trim_string</span>&#8216; from the end of &#8216;<span style="font-style: italic;">stringToTrim</span>&#8216;.<br />
<span style="font-weight: bold;">both -</span> This removes the &#8216;<span style="font-style: italic;">trim_string</span>&#8216; from the front and end of &#8216;<span style="font-style: italic;">stringToTrim</span>&#8216;.</p>
<p>By default if there is no choice give oracle will remove &#8216;<span style="font-style: italic;">trim_string</span>&#8216; from the front and end of &#8216;<span style="font-style: italic;">stringToTrim</span>&#8216;.</p>
<p><span style="font-weight: bold;">Examples:</span></p>
<p><span style="font-weight: bold;">1. Default Options</span></p>
<pre class="brush: css;">
SQL&gt; select trim ('  abcd ') from dual;

TRIM('ABCD')
abcd
SQL&gt;
</pre>
<p><span style="font-weight: bold;">2. Option &#8216;trailing&#8217; Example.</span></p>
<pre class="brush: css;">
SQL&gt; select trim(trailing 'C' from 'ABC') from dual;

TRIM(TRAILING'C'FROM'ABC')
AB
SQL&gt;
</pre>
<p><span style="font-weight: bold;">3. Option &#8216;leading&#8217; Example.</span></p>
<pre class="brush: css;">
 select trim(leading 'A' from 'ABC') from dual;
TRIM(LEADING'A'FROM'ABC')
BC
</pre>
<p><span style="font-weight: bold;">4. Option &#8216;both&#8217; Example</span></p>
<pre class="brush: css;">
SQL&gt; select trim(both 'A' from 'ABCA') from dual;
TRIM(BOTH'A'FROM'ABCA')
BC
</pre>
<p><span style="font-weight: bold;">5. Another example for option &#8216;both&#8217;.</span></p>
<pre class="brush: css;">
SQL&gt; select trim(both 'A' from 'AAAAABCAAAAAAAAA') from dual;
TRIM(BOTH'A'FROM'AAAAABCAAAAAA
BC
</pre>
<p><span style="font-weight: bold;">Other Functions</span> :&gt;&gt;&gt; <a href="../2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">DECODE </a>,<a href="../2008/12/03/sql-max-function-sql-max-examples/">MAX </a>,<a href="../2008/12/01/nvl-oracleplsql-nvl-function/">NVL </a>,<a href="../2008/12/01/oracleplsql-instr-function-instr-functions-case-sensitive-search/">INSTR </a>,<a href="http://plsqlworld.blogspot.com/2008/11/substr-functions-oracleplsql-substr.html">SUBSTR </a>,<a href="../2008/11/18/oracle-to_date-oracleplsql-to_date-function/">TO_DATE</a> ,<a href="../2008/11/19/oracle-to_char-function-and-usage/">TO_CHAR</a> ,<a href="../2008/11/20/oracle-plsql-to_timestamp-function-datetime-format-models/">TO_TIMESTAMP</a> ,<a href="../2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a>,<a href="../2008/11/18/plsql-extract-function-for-oracle-datetime/">Extract</a></p>
<p><span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-family: arial,helvetica,sans-serif; font-style: normal; font-variant: normal; font-size: 13px; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033;">Related Articles,</span></p>
<ul>
<li> <a title="Permalink to Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values" rel="bookmark" href="../2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values</a></li>
<li> <a title="Permalink to SQL: MAX Function | SQL Max examples" rel="bookmark" href="../2008/12/03/sql-max-function-sql-max-examples/">SQL: MAX Function | SQL Max examples</a></li>
<li> <a title="Permalink to SQL GROUP BY Statement | SQL GROUP BY Clause examples" rel="bookmark" href="../2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">SQL GROUP BY Statement | SQL GROUP BY Clause examples</a></li>
<li> <a title="Permalink to NVL | Oracle/PLSQL: NVL Function" rel="bookmark" href="../2008/12/01/nvl-oracleplsql-nvl-function/">NVL | Oracle/PLSQL: NVL Function</a></li>
<li> <a title="Permalink to SUBSTR functions | Oracle/PLSQL: Substr Function" rel="bookmark" href="../2008/12/01/substr-functions-oracleplsql-substr-function/">SUBSTR functions | Oracle/PLSQL: Substr Function</a></li>
<li> <a title="Permalink to Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search" rel="bookmark" href="../2008/12/01/oracleplsql-instr-function-instr-functions-case-sensitive-search/">Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search</a></li>
<li> <a title="Permalink to Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:" rel="bookmark" href="../2008/11/24/oracle-plsql-error-ora-06502-plsql-numeric-or-value-error/">Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:</a></li>
<li> <a title="Permalink to Oracle pl/sql error: ORA-06512" rel="bookmark" href="../2008/11/24/oracle-plsql-error-ora-06512/">Oracle pl/sql error: ORA-06512</a></li>
<li> <a title="Permalink to ORA-12154: TNS:could not resolve the connect identifier specified" rel="bookmark" href="../2008/11/24/ora-12154-tnscould-not-resolve-the-connect-identifier-specified/">ORA-12154: TNS:could not resolve the connect identifier specified</a></li>
<li> <a title="Permalink to Oracle timestamp format milliseconds| Oracle Date format" rel="bookmark" href="../2008/11/20/oracle-timestamp-format-milliseconds-oracle-date-format/">Oracle timestamp format milliseconds| Oracle Date format</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for TRIM" rel="tag" href="http://www.technorati.com/tag/TRIM" target="_blank">TRIM</a>, <a title="Link to Technorati Tag category for Oracle Trim Function" rel="tag" href="http://www.technorati.com/tag/Oracle+Trim+Function" target="_blank">Oracle Trim Function</a>, <a title="Link to Technorati Tag category for PLSQL TRIM Function" rel="tag" href="http://www.technorati.com/tag/PLSQL+TRIM+Function" target="_blank">PLSQL TRIM Function</a>, <a title="Link to Technorati Tag category for DECODE" rel="tag" href="http://www.technorati.com/tag/DECODE" target="_blank">DECODE</a>, <a title="Link to Technorati Tag category for MAX" rel="tag" href="http://www.technorati.com/tag/MAX" target="_blank">MAX</a>, <a title="Link to Technorati Tag category for NVL" rel="tag" href="http://www.technorati.com/tag/NVL" target="_blank">NVL</a>, <a title="Link to Technorati Tag category for INSTR" rel="tag" href="http://www.technorati.com/tag/INSTR" target="_blank">INSTR</a>, <a title="Link to Technorati Tag category for SUBSTR" rel="tag" href="http://www.technorati.com/tag/SUBSTR" target="_blank">SUBSTR</a>, <a title="Link to Technorati Tag category for TO_DATE" rel="tag" href="http://www.technorati.com/tag/TO_DATE" target="_blank">TO_DATE</a>, <a title="Link to Technorati Tag category for TO_CHAR" rel="tag" href="http://www.technorati.com/tag/TO_CHAR" target="_blank">TO_CHAR</a>, <a title="Link to Technorati Tag category for TO_TIMESTAMP" rel="tag" href="http://www.technorati.com/tag/TO_TIMESTAMP" target="_blank">TO_TIMESTAMP</a>, <a title="Link to Technorati Tag category for GROUP BY" rel="tag" href="http://www.technorati.com/tag/GROUP+BY" target="_blank">GROUP BY</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/12/04/oracle-trim-function-plsql-trim-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle Decode Function &#124; Use PLSQL DECODE function to handle NULL and default values</title>
		<link>http://plsql.globinch.com/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/</link>
		<comments>http://plsql.globinch.com/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 11:34:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=36</guid>
		<description><![CDATA[Oracle Decode Function &#124; Use PLSQL DECODE function to handle NULL and default values]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F03%2Foracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F03%2Foracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The <span style="font-weight: bold; color: #cc0000;">DECODE </span>function works as multiple if conditions or <span style="font-weight: bold; color: #009900;">CASE </span>statements.<br />
The <span style="font-weight: bold;">DECODE </span>function compares one expression to one or more expressions and returns the corresponding result expression.The default value will be returned when there is no match.It allows to transform data values at run time.</p>
<p>In newer versions of Oracle the <span style="font-weight: bold;">CASE </span>is used instead of <span style="font-weight: bold;">DECODE</span>.</p>
<p><span style="font-weight: bold; color: #009900;"><span style="text-decoration: underline;">Syntax:</span></span></p>
<pre class="brush: css;">
decode( expression , search_1 , result_value1 ,...., search_n , result_valuen , default_value )
</pre>
<p>At the end of the decode statement is the default value</p>
<p><span style="font-weight: bold;"><span style="text-decoration: underline;">Example:</span></span></p>
<p><span style="font-weight: bold;">Step1: </span>Create a table and insert records as follows</p>
<pre class="brush: css;">
SQL&gt; create table marks(name varchar2(20),grade number,mark number);

Table created

SQL&gt; insert into  marks values ('Chris',1,6);
SQL&gt; insert into  marks values ('James',3,4);
SQL&gt; insert into  marks values ('John',2,5);
SQL&gt; insert into  marks values ('Ram',1,6);
SQL&gt; insert into marks values('Kate', 4,3);

5 rows inserted.
</pre>
<p>Now let us get the details and based on the number value of the <span style="font-weight: bold;">Grade </span>let us get the detailed values.</p>
<pre class="brush: css;">
SQL&gt; select name,mark ,decode(grade,1,'GRADE A',2,'GRADE B',3,'GRADE C', 'Below Average') Grade from marks;
NAME                           MARK     GRADE
Chris                             6     GRADE A
James                             4     GRADE C
John                              4     GRADE B
Ram                               6     GRADE A
</pre>
<p>In the above example we use the <span style="font-weight: bold;">DECODE </span>function to check the grade value and display the Grades in textual form.There is a <span style="font-weight: bold; font-style: italic;">default</span> value &#8216;Below Average&#8217; when grades are not 1,2 or 3.</p>
<p><span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-family: arial,helvetica,sans-serif; font-style: normal; font-variant: normal; font-size: 13px; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033;">Related Articles,</span></p>
<ul>
<li> <a title="Permalink to Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values" rel="bookmark" href="../2008/12/04/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values</a></li>
<li> <a title="Permalink to SQL: MAX Function | SQL Max examples" rel="bookmark" href="../2008/12/04/2008/12/03/sql-max-function-sql-max-examples/">SQL: MAX Function | SQL Max examples</a></li>
<li> <a title="Permalink to SQL GROUP BY Statement | SQL GROUP BY Clause examples" rel="bookmark" href="../2008/12/04/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">SQL GROUP BY Statement | SQL GROUP BY Clause examples</a></li>
<li> <a title="Permalink to NVL | Oracle/PLSQL: NVL Function" rel="bookmark" href="../2008/12/04/2008/12/01/nvl-oracleplsql-nvl-function/">NVL | Oracle/PLSQL: NVL Function</a></li>
<li> <a title="Permalink to SUBSTR functions | Oracle/PLSQL: Substr Function" rel="bookmark" href="../2008/12/04/2008/12/01/substr-functions-oracleplsql-substr-function/">SUBSTR functions | Oracle/PLSQL: Substr Function</a></li>
<li> <a title="Permalink to Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search" rel="bookmark" href="../2008/12/04/2008/12/01/oracleplsql-instr-function-instr-functions-case-sensitive-search/">Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search</a></li>
<li> <a title="Permalink to Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:" rel="bookmark" href="../2008/12/04/2008/11/24/oracle-plsql-error-ora-06502-plsql-numeric-or-value-error/">Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:</a></li>
<li> <a title="Permalink to Oracle pl/sql error: ORA-06512" rel="bookmark" href="../2008/12/04/2008/11/24/oracle-plsql-error-ora-06512/">Oracle pl/sql error: ORA-06512</a></li>
<li> <a title="Permalink to ORA-12154: TNS:could not resolve the connect identifier specified" rel="bookmark" href="../2008/12/04/2008/11/24/ora-12154-tnscould-not-resolve-the-connect-identifier-specified/">ORA-12154: TNS:could not resolve the connect identifier specified</a></li>
<li> <a title="Permalink to Oracle timestamp format milliseconds| Oracle Date format" rel="bookmark" href="../2008/12/04/2008/11/20/oracle-timestamp-format-milliseconds-oracle-date-format/">Oracle timestamp format milliseconds| Oracle Date format</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for Oracle Decode Function" rel="tag" href="http://www.technorati.com/tag/Oracle+Decode+Function" target="_blank">Oracle Decode Function</a>, <a title="Link to Technorati Tag category for DECODE function" rel="tag" href="http://www.technorati.com/tag/DECODE+function" target="_blank">DECODE function</a>, <a title="Link to Technorati Tag category for plsql DECODE" rel="tag" href="http://www.technorati.com/tag/plsql+DECODE" target="_blank">plsql DECODE</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQL: MAX Function &#124; Oracle Max() examples</title>
		<link>http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/</link>
		<comments>http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 06:37:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=35</guid>
		<description><![CDATA[
		
		
		
		 
			
				
			
		
The Max() function is another much helpful function in SQL, the MAX function returns the maximum value of an expression. Read MIN() function here.
Syntax:

SELECT MAX(expression ) FROM tables WHERE ?;

Examples:   (See more example for Using MAX() function along with GROUP BY statement here. )
Step 1: Create a table &#8216;MyTable&#8217; as below.

SQL&#62; create [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "SQL: MAX Function | Oracle Max() examples";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F03%2Fsql-max-function-sql-max-examples%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F03%2Fsql-max-function-sql-max-examples%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The <strong style="color: #cc0000;">Max()</strong> function is another much helpful function in SQL, the <span style="font-weight: bold; color: #009900;">MAX function</span> returns the maximum value of an expression. Read <a href="http://plsql.globinch.com/2009/01/09/oracle-sql-min-function-min-function-in-sql/"><strong>MIN()</strong></a> function here.</p>
<p><span style="text-decoration: underline;"><strong>Syntax:</strong></span></p>
<pre class="brush: css;">
SELECT MAX(expression ) FROM tables WHERE ?;
</pre>
<p><span style="text-decoration: underline;"><strong>Examples: </strong> </span> (See more example for Using MAX() function along with <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">GROUP BY</a> statement <a href="http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">here</a>. )</p>
<p><span style="text-decoration: underline;"><strong>Step 1: </strong></span>Create a table &#8216;MyTable&#8217; as below.</p>
<pre class="brush: css;">
SQL&gt; create table MyTable (name varchar2(100),address varchar2(500),id number);
Table created
SQL&gt;
</pre>
<p><span style="text-decoration: underline;"><strong>Step 2: </strong></span>Insert few rows to &#8216;MyTable&#8217;.</p>
<pre class="brush: css;">
SQL&gt; insert into  mytable values ('name1','msg1',1);
1 row inserted
SQL&gt; insert into  mytable values ('name2','msg2',2);
1 row inserted
SQL&gt; insert into  mytable values ('name3','msg3',3);
1 row inserted
SQL&gt;
</pre>
<p><span style="text-decoration: underline;"><strong>Step 3:</strong> </span>Now let us select the maximum &#8216;id&#8217; from &#8216;Mytable&#8217;.</p>
<pre class="brush: css;">
SQL&gt; select max(id) from mytable;
MAX(ID)
3
</pre>
<p><span style="text-decoration: underline;"><strong>Step 4: </strong></span>Now let us retrive the complete row with maximum values of &#8216;id&#8217;;</p>
<pre class="brush: css;">
SQL&gt; select * from mytable where id = (select max(id) from mytable);
NAME                     MSG                     ID
name3                    msg3                     3&lt;
SQL&gt;
</pre>
<p><span style="color: #3333ff; text-decoration: underline;"><em> <span style="margin: 0px; padding: 5px 5px 0px; overflow: auto; clear: both; display: block; width: auto; font-family: arial,helvetica,sans-serif; font-style: normal; font-variant: normal; font-size: 13px; line-height: 18px; font-size-adjust: none; font-stretch: normal; font-weight: bold; color: #cc0033;">Related Articles,</span></em></span></p>
<ul>
<li> <a title="Permalink to Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values" rel="bookmark" href="../2008/12/04/2008/12/03/oracle-decode-function-use-plsql-decode-function-to-handle-null-and-default-values/">Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values</a></li>
<li> <a title="Permalink to SQL: MAX Function | SQL Max examples" rel="bookmark" href="../2008/12/04/2008/12/03/sql-max-function-sql-max-examples/">SQL: MAX Function | SQL Max examples</a></li>
<li> <a title="Permalink to SQL GROUP BY Statement | SQL GROUP BY Clause examples" rel="bookmark" href="../2008/12/04/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/">SQL GROUP BY Statement | SQL GROUP BY Clause examples</a></li>
<li> <a title="Permalink to NVL | Oracle/PLSQL: NVL Function" rel="bookmark" href="../2008/12/04/2008/12/01/nvl-oracleplsql-nvl-function/">NVL | Oracle/PLSQL: NVL Function</a></li>
<li> <a title="Permalink to SUBSTR functions | Oracle/PLSQL: Substr Function" rel="bookmark" href="../2008/12/04/2008/12/01/substr-functions-oracleplsql-substr-function/">SUBSTR functions | Oracle/PLSQL: Substr Function</a></li>
<li> <a title="Permalink to Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search" rel="bookmark" href="../2008/12/04/2008/12/01/oracleplsql-instr-function-instr-functions-case-sensitive-search/">Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search</a></li>
<li> <a title="Permalink to Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:" rel="bookmark" href="../2008/12/04/2008/11/24/oracle-plsql-error-ora-06502-plsql-numeric-or-value-error/">Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:</a></li>
<li> <a title="Permalink to Oracle pl/sql error: ORA-06512" rel="bookmark" href="../2008/12/04/2008/11/24/oracle-plsql-error-ora-06512/">Oracle pl/sql error: ORA-06512</a></li>
<li> <a title="Permalink to ORA-12154: TNS:could not resolve the connect identifier specified" rel="bookmark" href="../2008/12/04/2008/11/24/ora-12154-tnscould-not-resolve-the-connect-identifier-specified/">ORA-12154: TNS:could not resolve the connect identifier specified</a></li>
<li> <a title="Permalink to Oracle timestamp format milliseconds| Oracle Date format" rel="bookmark" href="../2008/12/04/2008/11/20/oracle-timestamp-format-milliseconds-oracle-date-format/">Oracle timestamp format milliseconds| Oracle Date format</a></li>
</ul>
<p style="text-align: right; font-size: 9px; display: none;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for SQL MAX Function" rel="tag" href="http://www.technorati.com/tag/SQL+MAX+Function" target="_blank">SQL MAX Function</a>, <a title="Link to Technorati Tag category for SQL MAX" rel="tag" href="http://www.technorati.com/tag/SQL+MAX" target="_blank">SQL MAX</a>, <a title="Link to Technorati Tag category for Max funstion" rel="tag" href="http://www.technorati.com/tag/Max+funstion" target="_blank">Max funstion</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/12/03/sql-max-function-sql-max-examples/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SQL GROUP BY Statement &#124; Oracle GROUP BY Clause examples</title>
		<link>http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/</link>
		<comments>http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 06:30:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=34</guid>
		<description><![CDATA[The GROUP BY statement is used in conjunction with the aggregate functions like SUM to provide means of grouping the result by certain table column or columns.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "SQL GROUP BY Statement | Oracle GROUP BY Clause examples";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F03%2Fsql-group-by-statement-sql-group-by-clause-examples%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F03%2Fsql-group-by-statement-sql-group-by-clause-examples%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The <strong style="color: #990000;">GROUP BY</strong> statement is used in conjunction with the aggregate functions like <strong>SUM</strong><a href="http://plsqlworld.blogspot.com/2008/12/sql-max-function-sql-max-examples.html"> </a>to provide means of grouping the result by certain table column or columns.<span class="fullpost"> </span></p>
<p><span style="font-weight: bold;"><span style="text-decoration: underline;">Syntax:</span></span></p>
<pre class="brush: css;">
SQL&gt; SELECT columnName, aggregate_function(columnName)
FROM tableName
WHERE
GROUP BY columnName
</pre>
<p><strong><span style="text-decoration: underline;">Examples :</span></strong></p>
<p><strong><span style="text-decoration: underline;">Step 1:</span></strong> Create a table &#8216;MyTable&#8217; as below.</p>
<pre class="brush: css;">
SQL&gt; create table MyTable (name varchar2(100),address varchar2(500),marks number);

Table created
</pre>
<p><strong><span style="text-decoration: underline;">Step 2:</span> </strong>Insert few rows to &#8216;MyTable&#8217;.</p>
<pre class="brush: css;">
SQL&gt; insert into  mytable values ('Chris','Add1',1);
SQL&gt; insert into  mytable values ('John','Add2',2);
SQL&gt; insert into  mytable values ('John','Add2',3);
SQL&gt; insert into  mytable values ('John','Add2',4);
SQL&gt; insert into  mytable values ('Chris','Add1',5);
5 rows inserted
</pre>
<p><strong><span style="text-decoration: underline;">Step 3: </span></strong>Now let us calculate the total marks for Chris and John using GROUP BY Clause.</p>
<pre class="brush: css;">
SQL&gt; select name,SUM(marks) from mytable GROUP BY name;
NAME                                         SUM(MARKS)
John                                                        9
Chris                                                       6
</pre>
<p style="text-align: right; font-size: 9px; display: none;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for SQL GROUP BY Clause" rel="tag" href="http://www.technorati.com/tag/SQL+GROUP+BY+Clause" target="_blank">SQL GROUP BY Clause</a>, <a title="Link to Technorati Tag category for SQL GROUP BY" rel="tag" href="http://www.technorati.com/tag/SQL+GROUP+BY" target="_blank">SQL GROUP BY</a>, <a title="Link to Technorati Tag category for SQL GROUP BY Statement" rel="tag" href="http://www.technorati.com/tag/SQL+GROUP+BY+Statement" target="_blank">SQL GROUP BY Statement</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/12/03/sql-group-by-statement-sql-group-by-clause-examples/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NVL &#124; Oracle/PLSQL: NVL Function</title>
		<link>http://plsql.globinch.com/2008/12/01/nvl-oracleplsql-nvl-function/</link>
		<comments>http://plsql.globinch.com/2008/12/01/nvl-oracleplsql-nvl-function/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 07:55:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=33</guid>
		<description><![CDATA[NVL function is used to substitute a value when a null value is encountered.This is useful in PL/SQL programming where we can supply default values when there is a chance of getting null at run time or to provide useful logging messages.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 50px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		yahooBuzzArticleHeadline = "NVL | Oracle/PLSQL: NVL Function";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/12/01/nvl-oracleplsql-nvl-function/";
		yahooBuzzArticleSummary = "";
		//-->
		</script>
		<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"> </script></div><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F01%2Fnvl-oracleplsql-nvl-function%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F12%2F01%2Fnvl-oracleplsql-nvl-function%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>NVL function is used to substitute a value when a null value is encountered.This is useful in PL/SQL programming where we can supply default values when there is a chance of getting null at run time or to provide useful logging messages.</p>
<p><span style="font-weight: bold;">Example is given below.</span></p>
<pre class="brush: css;">
SQL&gt; set serveroutput on;
SQL&gt; -- Created on 12/1/2008 by PLSQLTech Tips
SQL&gt; declare
-- Local variables here
myStr varchar2(100);
begin
--Initialize the String
myStr := 'This is my string';
dbms_output.put_line(nvl(myStr,'This is to replace if string is null'));
--Now set the String to null;
myStr := null;
dbms_output.put_line(nvl(myStr,'This is to replace if string is null'));
end;
/

This is my string
This is to replace if string is null
PL/SQL procedure successfully completed.
SQL&gt;
</pre>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for NVL" rel="tag" href="http://www.technorati.com/tag/NVL" target="_blank">NVL</a>, <a title="Link to Technorati Tag category for oracle NVL" rel="tag" href="http://www.technorati.com/tag/oracle+NVL" target="_blank">oracle NVL</a>, <a title="Link to Technorati Tag category for plsql NVL Function" rel="tag" href="http://www.technorati.com/tag/plsql+NVL+Function" target="_blank">plsql NVL Function</a>, <a title="Link to Technorati Tag category for oracle  NVL Function" rel="tag" href="http://www.technorati.com/tag/oracle+NVL+Function" target="_blank">oracle  NVL Function</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/12/01/nvl-oracleplsql-nvl-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

