<?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; Data types</title>
	<atom:link href="http://plsql.globinch.com/category/plsql-data-types/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 comparing dates : dates, oracle, date comparison in oracle pl/sql</title>
		<link>http://plsql.globinch.com/2008/11/19/oracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql/</link>
		<comments>http://plsql.globinch.com/2008/11/19/oracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 09:08:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Date]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=22</guid>
		<description><![CDATA[How to compare dates in oracle?There are a number of ways you can compare two dates in oracle to check which is greater or which is small.This is particularly useful when we do operations based on certain date conditions.This is used along with to_date and other date functions.
]]></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 comparing dates : dates, oracle, date comparison in oracle pl/sql";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/11/19/oracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql/";
		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%2F11%2F19%2Foracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F11%2F19%2Foracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>How to compare dates in oracle?There are a number of ways you can compare two dates in oracle to check which is greater or which is small.This is particularly useful when we do operations based on certain date conditions.This is used along with <strong><a href="http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/">to_date</a> </strong>and other date functions.<span class="fullpost"><br />
The following example illustrates the<span style="font-weight: bold; color: #009900;"> date comparison </span>in Oracle pl/sql.</p>
<pre class="brush: css;">
SQL&gt; SET SERVEROUTPUT ON;
SQL&gt;
SQL&gt; -- Created on 11/19/2008 by Globinch PLSQLTIPS
SQL&gt; declare
-- Local variables here
test_Date DATE;
begin
   --- Initialize the test date a future date.
      test_Date := to_date('12/12/2008','DD/MM/YYYY');
      if test_date&gt;sysdate then
         dbms_output.put_line('The date :' || test_Date||': This is a future date!');
      end if;
      ----Now subtract 60 days from the test date
      test_Date := test_Date - 60;
      if test_date&lt;sysdate
            dbms_output.put_line('The date :' || test_Date||': This is a Past date!');
      end if;
     --- Now make test date current date
     test_Date :=  sysdate;
     if test_date = sysdate then
         dbms_output.put_line('The date :' || test_Date||': Date is a today!');
     end if;
 end;
/

The date :12-DEC-08: This is a future date!
The date :13-OCT-08: This is a Past date!
The date :19-NOV-08: Date is a today!

PL/SQL procedure successfully completed.

SQL&gt;
</pre>
<p><span style="color: #3333ff; font-style: italic;">Related articles on oracle DATE , TIMESTAMP etc</span></span></p>
<ul>
<li><a href="http://plsql.globinch.com/2008/11/18/ora-01882-timezone-region-not-found-oracle-error/"><strong> </strong><strong>ORA-01882: TIMEZONE REGION NOT FOUND |Oracle Error</strong></a></li>
<li><a href="../2008/11/18/plsql-extract-function-for-oracle-datetime/">PL/SQL EXTRACT function for oracle datetime</a></li>
</ul>
<ul>
<li><a href="../2008/11/18/2008/11/18/2008/11/18/2008/11/13/alter-table-to-add-primary-key-in-oracle-oracle-alter-table/"><strong>ALTER TABLE to ADD PRIMARY KEY in Oracle| Oracle ALTER TABLE</strong></a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/oracle-date-difference-date-difference-in-sql-and-plsql/">oracle date difference | date difference in sql an…</a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/18/2008/11/18/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/"><strong>DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle</strong></a><strong> </strong></li>
<li><strong><a href="../2008/11/18/2008/11/18/2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></strong></li>
</ul>
<ul>
<li><a href="../2008/11/18/2008/11/18/2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/05/database-schema-oracle-schema-objects-what-is-database-schema/"><strong>Database Schema | Oracle Schema Objects | What is database schema?</strong></a></li>
</ul>
<ul>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/05/database-schema-oracle-schema-objects-what-is-database-schema/"><strong>Database Schema | Oracle Schema Objects | What is database schema?</strong></a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/04/autonomous-transactions-in-plsql/"><strong>Autonomous Transactions in PL/SQL</strong></a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/sql-transaction-statements-transaction-management/">SQL – Transaction Statements -Transaction Manageme…</a></li>
</ul>
<ul>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/savepoints-in-sql-transactions-savepoint/"><strong>Savepoints In SQL Transactions. – SAVEPOINT</strong></a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/31/oracle-tablespace-and-datafiles-introduction/">Oracle Tablespace, and Datafiles – Introduction</a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></li>
<li><a href="../2008/11/18/2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/28/finding-database-objects-finding-valid-and-invalid-objects-and-finding-object-counts-sql-tips/">FINDING database objects, finding valid and INVALI…</a></li>
</ul>
<p style="text-align: right; font-size: 9px;"><span class="fullpost"> </span>Technorati Tags:<br />
<a title="Link to Technorati Tag category for Oracle comparing dates" rel="tag" href="http://www.technorati.com/tag/Oracle+comparing+dates" target="_blank">Oracle comparing dates</a>, <a title="Link to Technorati Tag category for dates" rel="tag" href="http://www.technorati.com/tag/dates" target="_blank">dates</a>, <a title="Link to Technorati Tag category for oracle" rel="tag" href="http://www.technorati.com/tag/oracle" target="_blank">oracle</a>, <a title="Link to Technorati Tag category for Comparing Dates in oracle pl/sql" rel="tag" href="http://www.technorati.com/tag/Comparing+Dates+in+oracle+pl/sql" target="_blank">Comparing Dates in oracle pl/sql</a>, <a title="Link to Technorati Tag category for sql dates" rel="tag" href="http://www.technorati.com/tag/sql+dates" target="_blank">sql dates</a>, <a title="Link to Technorati Tag category for date comparison" rel="tag" href="http://www.technorati.com/tag/date+comparison" target="_blank">date comparison</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/11/19/oracle-comparing-dates-dates-oracle-date-comparison-in-oracle-plsql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle Dates and Times &#124;SYSDATE&#124;CURRENT_TIMESTAMP &#124;SYSTIMESTAMP &#124;DBTIMEZONE &#124;LOCALTIMESTAMP</title>
		<link>http://plsql.globinch.com/2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/</link>
		<comments>http://plsql.globinch.com/2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 13:32:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Date]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=19</guid>
		<description><![CDATA[The DATE type is stored in a special internal format that includes not just the month, day, and year, but also the hour, minute, and second.There are a number of key words and functions provided by oracle to use the date and timestamp data types in much flexible ways.
]]></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 Dates and Times |SYSDATE|CURRENT_TIMESTAMP |SYSTIMESTAMP |DBTIMEZONE |LOCALTIMESTAMP";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/";
		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%2F11%2F18%2Foracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F11%2F18%2Foracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The <a href="http://plsql.globinch.com/2008/11/18/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/"><span style="font-weight: bold; color: #009900;">DATE</span><span style="color: #009900;"> </span></a>type is stored in a special <a href="http://plsql.globinch.com/2008/11/18/2008/11/13/2008/11/13/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/"><strong>internal format</strong></a> that includes not just the month, day, and year, but also the hour, minute, and second.There are a number of key words and functions provided by oracle to use the <a href="http://plsql.globinch.com/2008/11/18/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/">date </a>and <a href="http://plsql.globinch.com/2008/11/18/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/">timestamp </a>data types in  much flexible ways.<span class="fullpost"><br />
<span style="font-weight: bold; color: #009900;"><br />
TIMESTAMP </span><span style="color: #009900;">datatype</span><br />
In addition to the DATE data type Oracle has <span style="font-weight: bold;">TIMESTAMP </span>data type which stores all the information that the DATE data type stores, but also includes fractional seconds.</span></p>
<p><span style="font-weight: bold; color: #009900;">CURRENT_TIMESTAMP</span> will give the current time with all details.<br />
<span style="font-weight: bold; color: #009900;">DBTIMEZONE</span> will give the database timezone set.</p>
<p><span style="font-style: italic; color: #3333ff;">Read the below articles to know more about time and date features in oracle</span><br />
<span style="font-size: 85%;"><a href="http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/">oracle to_date | Oracle/PLSQL: To_Date Function</a><br />
<a href="http://plsqlworld.blogspot.com/2008/11/oracle-date-difference-date-difference.html">oracle date difference | date difference in sql an&#8230;</a><br />
<a href="http://plsql.globinch.com/2008/11/18/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/">DATE Data type in Oracle|Oracle Dates and Times|Da&#8230;</a><br />
<a href="http://plsql.globinch.com/2008/11/18/2008/11/13/2008/11/13/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma&#8230;</a></span></p>
<p><span style="font-weight: bold; color: #cc0000;">Examples for all the above features give below.</span></p>
<p><span style="font-weight: bold; color: #000099;">The current Time :</span></p>
<pre class="brush: css;">
SQL&gt; select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as &quot;Now&quot; from dual;
Now
Tue 18-Nov-2008 18:47:25
</pre>
<p><span style="font-weight: bold; color: #333399;">TIMESTAMP Example</span></p>
<pre class="brush: css;">
SQL&gt; SELECT CAST(sysdate AS TIMESTAMP) &quot;Date&quot; FROM dual;
Date
18-NOV-08 06.50.41.000000 PM
SQL&gt;
</pre>
<p><span style="font-weight: bold; color: #000099;">DATE and Time formating Example</span></p>
<pre class="brush: css;">
SQL&gt; SELECT TO_CHAR(sysdate,'Dy MM/DD/YYYY HH24:MI:SS') &quot;Current Time&quot; from dual;
Current Time
Tue 11/18/2008 18:51:49
SQL&gt;
</pre>
<p><span style="font-weight: bold; color: #000099;">SYSTIMESTAMP Example</span></p>
<pre class="brush: css;">
SQL&gt; SELECT TO_CHAR(SYSTIMESTAMP,'Dy MM/DD/YYYY HH24:MI:SS') &quot;Current Time&quot; from dual;
Current Time
Tue 11/18/2008 18:52:39
SQL&gt;
</pre>
<p><span style="font-weight: bold; color: #000099;">CURRENT_TIMESTAMP Example</span></p>
<pre class="brush: css;">
SQL&gt; SELECT  CURRENT_TIMESTAMP FROM dual;
CURRENT_TIMESTAMP
18-NOV-08 06.53.42.628000 PM +05:30
SQL&gt;
</pre>
<p><span style="font-weight: bold; color: #000099;">DBTIMEZONE Example </span></p>
<pre class="brush: css;">
SQL&gt; SELECT DBTIMEZONE FROM dual;
DBTIMEZONE
+00:00
SQL&gt;
</pre>
<p><span style="font-weight: bold; color: #000099;">LOCALTIMESTAMP and CURRENT_TIMESTAMP Example</span></p>
<pre class="brush: css;">
SQL&gt; SELECT CURRENT_TIMESTAMP,  LOCALTIMESTAMP FROM dual;
CURRENT_TIMESTAMP                                 LOCALTIMESTAMP
18-NOV-08 06.55.55.067000 PM +05:30               18-NOV-08 06.55.55.067000 PM

SQL&gt;
</pre>
<p><span style="font-weight: bold; color: #3333ff; font-style: italic;">Also Read,</span></p>
<ul>
<li><a href="../2008/11/13/alter-table-to-add-primary-key-in-oracle-oracle-alter-table/"><strong>ALTER TABLE to ADD PRIMARY KEY in Oracle| Oracle ALTER TABLE</strong></a></li>
<li><a href="http://plsql.globinch.com/2008/11/13/oracle-date-difference-date-difference-in-sql-and-plsql/">oracle date difference | date difference in sql an…</a></li>
<li><a href="../2008/11/18/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/"><strong>DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle</strong></a><strong> </strong></li>
<li><strong><a href="../2008/11/18/2008/11/13/2008/11/13/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></strong></li>
</ul>
<ul>
<li><a href="../2008/11/18/2008/11/13/2008/11/13/2008/11/05/database-schema-oracle-schema-objects-what-is-database-schema/"><strong>Database Schema | Oracle Schema Objects | What is database schema?</strong></a></li>
<li><a href="../2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/04/autonomous-transactions-in-plsql/"><strong>Autonomous Transactions in PL/SQL</strong></a></li>
<li><a href="../2008/11/18/2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/sql-transaction-statements-transaction-management/">SQL – Transaction Statements -Transaction Manageme…</a></li>
</ul>
<p>______________________________________________________________________</p>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for Oracle Date" rel="tag" href="http://www.technorati.com/tag/Oracle+Date" target="_blank">Oracle Date</a>, <a title="Link to Technorati Tag category for Oracle Time" rel="tag" href="http://www.technorati.com/tag/Oracle+Time" target="_blank">Oracle Time</a>, <a title="Link to Technorati Tag category for Oracle Timestamp" rel="tag" href="http://www.technorati.com/tag/Oracle+Timestamp" target="_blank">Oracle Timestamp</a>, <a title="Link to Technorati Tag category for Oracle Dates and Times" rel="tag" href="http://www.technorati.com/tag/Oracle+Dates+and+Times" target="_blank">Oracle Dates and Times</a>, <a title="Link to Technorati Tag category for SYSDATE" rel="tag" href="http://www.technorati.com/tag/SYSDATE" target="_blank">SYSDATE</a>, <a title="Link to Technorati Tag category for CURRENT_TIMESTAMP" rel="tag" href="http://www.technorati.com/tag/CURRENT_TIMESTAMP" target="_blank">CURRENT_TIMESTAMP</a>, <a title="Link to Technorati Tag category for SYSTIMESTAMP" rel="tag" href="http://www.technorati.com/tag/SYSTIMESTAMP" target="_blank">SYSTIMESTAMP</a>, <a title="Link to Technorati Tag category for DBTIMEZONE" rel="tag" href="http://www.technorati.com/tag/DBTIMEZONE" target="_blank">DBTIMEZONE</a>, <a title="Link to Technorati Tag category for LOCALTIMESTAMP" rel="tag" href="http://www.technorati.com/tag/LOCALTIMESTAMP" target="_blank">LOCALTIMESTAMP</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>oracle to_date &#124; Oracle/PLSQL: To_Date Function</title>
		<link>http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/</link>
		<comments>http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 12:16:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Fundamentals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=18</guid>
		<description><![CDATA[The purpose of TO_DATE in Oracle pl/sql is to convert char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type to a value of DATE datatype.Or more generically the Oracle to_date function is used to change a test string (or variable) into an internal date format.]]></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 to_date | Oracle/PLSQL: To_Date Function";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-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%2F11%2F18%2Foracle-to_date-oracleplsql-to_date-function%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F11%2F18%2Foracle-to_date-oracleplsql-to_date-function%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The purpose of <span style="font-weight: bold; color: #009900;">TO_DATE </span>in Oracle pl/sql is to convert char of <span style="font-style: italic; color: #009900;">CHAR, VARCHAR2, NCHAR, or NVARCHAR2 </span>data type to a value of <a href="http://plsql.globinch.com/2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/">DATE datatype</a>.Or more generically the Oracle to_date function is used to change a test string (or variable) into an internal <a href="http://plsql.globinch.com/2008/11/13/2008/11/13/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/"><strong>date format</strong></a>.<span class="fullpost"> </span></p>
<p><span style="font-weight: bold; color: #cc0000;">Syntax</span><br />
to_date( stringDate, [ format_mask ], [ nls_param ] )</p>
<p><span style="font-style: italic; color: #3333ff;">Where </span><br />
<span style="font-weight: bold;">stringDate  :</span> is the string to convert to date<br />
<span style="font-weight: bold;">format_mask :</span> is the format that will be used to convert <span style="font-style: italic;">stringDate </span>to a date.<br />
<span style="font-weight: bold;">nls_param   :</span> is the <span style="font-weight: bold;">nls </span>language used to convert <span style="font-style: italic;">stringDate </span>to a date.</p>
<p><span style="font-weight: bold; color: #009900;">Examples:</span></p>
<pre class="brush: css;">
SQL&gt; select to_date('JAN/12/2009' ,'MON-DD-YYYY HH24:MI:SS') THE_DATE from dual;
THE_DATE
1/12/2009

SQL&gt; select to_date('20080312','YYYYMMDD') from dual;

TO_DATE('20080312','YYYYMMDD')
3/12/2008
SQL&gt; select to_date('20080312','YYYYDDMM') from dual;

TO_DATE('20080312','YYYYDDMM')
12/3/2008

SQL&gt; select to_date('2006/11/14 18', 'yyyy/mm/dd hh24') from dual;

TO_DATE('2006/11/1418','YYYY/M
11/14/2006 6:00:00 PM

SQL&gt; SELECT TO_DATE('January 15, 1989, 11:00 A.M.', 'Month dd, YYYY, HH:MI A.M.','NLS_DATE_LANGUAGE = American')FROM DUAL;
TO_DATE('JANUARY15,1989,11:00A
1/15/1989 11:00:00 AM
SQL&gt;
</pre>
<p><span style="font-weight: bold; font-style: italic; color: #3333ff;">Also Read,</span></p>
<ul>
<li><strong> </strong><a href="http://plsql.globinch.com/2008/11/13/alter-table-to-add-primary-key-in-oracle-oracle-alter-table/"><strong>ALTER TABLE to ADD PRIMARY KEY in Oracle| Oracle ALTER TABLE</strong></a></li>
<li><a onclick="javascript:pageTracker._trackPageview('/outbound/article/http://plsqlworld.blogspot.com/2008/11/oracle-date-difference-date-difference.html');" href="http://plsqlworld.blogspot.com/2008/11/oracle-date-difference-date-difference.html">oracle date difference | date difference in sql an…</a></li>
<li><a href="../2008/11/13/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/"><strong>DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle</strong></a><strong> </strong></li>
<li><strong><a href="../2008/11/13/2008/11/13/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></strong></li>
</ul>
<ul>
<li><a href="../2008/11/13/2008/11/13/2008/11/05/database-schema-oracle-schema-objects-what-is-database-schema/"><strong>Database Schema | Oracle Schema Objects | What is database schema?</strong></a></li>
<li><a href="../2008/11/13/2008/11/13/2008/11/13/2008/11/04/autonomous-transactions-in-plsql/"><strong>Autonomous Transactions in PL/SQL</strong></a></li>
<li><a href="../2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/sql-transaction-statements-transaction-management/">SQL – Transaction Statements -Transaction Manageme…</a></li>
</ul>
<ul>
<li><a href="../2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/savepoints-in-sql-transactions-savepoint/"><strong>Savepoints In SQL Transactions. – SAVEPOINT</strong></a></li>
<li><a href="../2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/31/oracle-tablespace-and-datafiles-introduction/">Oracle Tablespace, and Datafiles – Introduction</a></li>
<li><a href="../2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></li>
<li><a href="../2008/11/13/2008/11/13/2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/28/finding-database-objects-finding-valid-and-invalid-objects-and-finding-object-counts-sql-tips/">FINDING database objects, finding valid and INVALI…</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<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 oracle TO_DATE" rel="tag" href="http://www.technorati.com/tag/oracle+TO_DATE" target="_blank">oracle TO_DATE</a>, <a title="Link to Technorati Tag category for pl/sql TO_DATE" rel="tag" href="http://www.technorati.com/tag/pl/sql+TO_DATE" target="_blank">pl/sql TO_DATE</a>, <a title="Link to Technorati Tag category for sql TO_DATE" rel="tag" href="http://www.technorati.com/tag/sql+TO_DATE" target="_blank">sql TO_DATE</a>, <a title="Link to Technorati Tag category for oracle date conversion" rel="tag" href="http://www.technorati.com/tag/oracle+date+conversion" target="_blank">oracle date conversion</a>, <a title="Link to Technorati Tag category for string to date" rel="tag" href="http://www.technorati.com/tag/string+to+date" target="_blank">string to date</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/11/18/oracle-to_date-oracleplsql-to_date-function/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Oracle date difference &#124; date difference in sql and PL/SQL</title>
		<link>http://plsql.globinch.com/2008/11/13/oracle-date-difference-date-difference-in-sql-and-plsql/</link>
		<comments>http://plsql.globinch.com/2008/11/13/oracle-date-difference-date-difference-in-sql-and-plsql/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 07:18:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Date]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=16</guid>
		<description><![CDATA[Oracle maintains the SYSDATE pseudo-column to show the current system date and time.
How to find the difference between two dates in Oracle? The following examples gives different useful methods to do this.]]></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 date difference | date difference in sql and PL/SQL";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/11/13/oracle-date-difference-date-difference-in-sql-and-plsql/";
		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%2F11%2F13%2Foracle-date-difference-date-difference-in-sql-and-plsql%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F11%2F13%2Foracle-date-difference-date-difference-in-sql-and-plsql%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Oracle maintains the <span style="font-weight: bold; color: #cc0000;">SYSDATE </span>pseudo-column to show the current system date and time.<br />
<span style="font-weight: bold; font-style: italic; color: #6600cc;">How to find the difference between two dates in Oracle?</span><span style="color: #6600cc;"><span style="color: #000000;"> The following examples gives different useful methods to do this.</span></span><span class="fullpost"> </span></p>
<p>With Oracle <a href="http://plsqlworld.blogspot.com/2008/11/oracle-dates-and-times.html">Dates</a>, this is simple by subtracting the dates and do some minor modification to get get Days/Hours/Minutes/Seconds between the dates.</p>
<p><span style="font-style: italic; color: #6600cc; font-weight: bold;">See the following example.</span></p>
<pre class="brush: css;">
SQL&gt; set serveroutput on;
SQL&gt; declare
   today       date;
   nextday       date;
begin
  today := sysdate;&lt;
   --Add 1 day to sysdate
   nextday := sysdate+1;
   dbms_output.put_line('&gt;&gt; Tomorrow is ' || (nextday-today) || ' day ahead of today' );
   dbms_output.put_line('&gt;&gt; Tomorrow is ' || (nextday-today)*24 || ' hours ahead of today ' );
   dbms_output.put_line('&gt;&gt; Tomorrow is ' || (nextday-today)*24*60 || '  minutes ahead of today' );
   dbms_output.put_line('&gt;&gt; Tomorrow is ' || (nextday-today)*24*60*60 || ' seconds ahead of today');
  end;
 /

 &gt;&gt; Tomorrow is 1 day ahead of today
 &gt;&gt; Tomorrow is 24 hours ahead of today
 &gt;&gt; Tomorrow is 1440  minutes ahead of today
 &gt;&gt; Tomorrow is 86400 seconds ahead of today&lt;/span&gt;

PL/SQL procedure successfully completed.
</pre>
<p>Adding 1 to <span style="font-weight: bold;">SYSDATE </span>will advance the date by 1 day. By adding fractions to sysdate we can advance by hours,minutes and seconds.</p>
<p><span style="font-weight: bold;">Current time  :SYSDATE</span><br />
<span style="font-weight: bold;">Tomorrow  :SYSDATE+1</span><br />
<span style="font-weight: bold;">One hour from now :SYSDATE + 1/24</span><br />
<span style="font-weight: bold;">One minute from now :SYSDATE + 1/1440</span><br />
<span style="font-weight: bold;">Five second from now :SYSDATE + 5/86400</span></p>
<p>See the example below,</p>
<pre class="brush: css;">
SQL&gt; set serveroutput on;
SQL&gt;  declare
  begin
     dbms_output.put_line('&gt;&gt; Current Time        :' || TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'));
    dbms_output.put_line('&gt;&gt; Tomorrow is         :' || TO_CHAR((SYSDATE + 1),'DD-MON-YYYY HH24:MI:SS'));
    dbms_output.put_line('&gt;&gt; One hour from now   :' || TO_CHAR((SYSDATE + 1/24),'DD-MON-YYYY HH24:MI:SS'));
    dbms_output.put_line('&gt;&gt; One minute from now :' || TO_CHAR((SYSDATE + 1/1440),'DD-MON-YYYY HH24:MI:SS'));
    dbms_output.put_line('&gt;&gt; Five second from now: ' || TO_CHAR((SYSDATE + 5/86400),'DD-MON-YYYY HH24:MI:SS'));
end;

&gt;&gt; Current Time        :13-NOV-2008 12:45:29
&gt;&gt; Tomorrow is         :14-NOV-2008 12:45:29
&gt;&gt; One hour from now   :13-NOV-2008 13:45:29
&gt;&gt; One minute from now :13-NOV-2008 12:46:29
&gt;&gt; Five second from now: 13-NOV-2008 12:45:34
PL/SQL procedure successfully completed.
SQL&gt;
</pre>
<p><strong>Related Topics,</strong></p>
<p><strong> </strong><a href="http://plsql.globinch.com/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/"><strong>DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle</strong></a><br />
<strong><a href="../2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></strong></p>
<p>Also Read,</p>
<ul>
<li><strong> </strong><a href="../2008/11/05/database-schema-oracle-schema-objects-what-is-database-schema/"><strong>Database Schema | Oracle Schema Objects | What is database schema?</strong></a></li>
<li><a href="../2008/11/13/2008/11/04/autonomous-transactions-in-plsql/"><strong>Autonomous Transactions in PL/SQL</strong></a></li>
<li><a href="../2008/11/13/2008/11/05/2008/11/04/sql-transaction-statements-transaction-management/">SQL – Transaction Statements -Transaction Manageme…</a></li>
</ul>
<ul>
<li><a href="../2008/11/13/2008/11/05/2008/11/04/2008/11/04/savepoints-in-sql-transactions-savepoint/"><strong>Savepoints In SQL Transactions. – SAVEPOINT</strong></a></li>
<li><a href="../2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/31/oracle-tablespace-and-datafiles-introduction/">Oracle Tablespace, and Datafiles – Introduction</a></li>
<li><a href="../2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></li>
<li><a href="../2008/11/13/2008/11/05/2008/11/04/2008/11/04/2008/10/28/finding-database-objects-finding-valid-and-invalid-objects-and-finding-object-counts-sql-tips/">FINDING database objects, finding valid and INVALI…</a></li>
<li><a href="../2008/11/13/2008/11/05/2008/11/04/2008/11/04/2007/06/05/oracle-data-types/">Oracle  Data types</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for oracle date difference" rel="tag" href="http://www.technorati.com/tag/oracle+date+difference" target="_blank">oracle date difference</a>, <a title="Link to Technorati Tag category for oracle date" rel="tag" href="http://www.technorati.com/tag/oracle+date" target="_blank">oracle date</a>, <a title="Link to Technorati Tag category for date difference" rel="tag" href="http://www.technorati.com/tag/date+difference" target="_blank">date difference</a>, <a title="Link to Technorati Tag category for date difference sql" rel="tag" href="http://www.technorati.com/tag/date+difference+sql" target="_blank">date difference sql</a>, <a title="Link to Technorati Tag category for date difference pl/sql" rel="tag" href="http://www.technorati.com/tag/date+difference+pl/sql" target="_blank">date difference pl/sql</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/11/13/oracle-date-difference-date-difference-in-sql-and-plsql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DATE Data type in Oracle&#124;Oracle Dates and Times&#124;Dates in OracleDATE Data type in Oracle&#124;Oracle Dates and Times&#124;Dates in Oracle</title>
		<link>http://plsql.globinch.com/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/</link>
		<comments>http://plsql.globinch.com/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 06:35:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Date]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=15</guid>
		<description><![CDATA[In Oracle Date data is stored in fixed-length fields of seven bytes each, corresponding to century, year, month, day, hour, minute, and second. (Also Read Formatting date in SQL (Oracle) -Simple date forma...) .]]></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 = "DATE Data type in Oracle|Oracle Dates and Times|Dates in OracleDATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/";
		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%2F11%2F13%2Fdate-data-type-in-oracleoracle-dates-and-timesdates-in-oracle%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F11%2F13%2Fdate-data-type-in-oracleoracle-dates-and-timesdates-in-oracle%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>In Oracle<span style="font-weight: bold; color: #cc0000;"> Date</span> data is stored in fixed-length fields of seven bytes each, corresponding to century, year, month, day, hour, minute, and second. (Also Read <a href="http://plsql.globinch.com/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma&#8230;</a>) .The <a href="http://plsql.globinch.com/2008/11/18/oracle-dates-and-times-sysdatecurrent_timestamp-systimestamp-dbtimezone-localtimestamp/"><strong>date </strong></a>and <a href="http://plsql.globinch.com/2008/11/20/oracle-date-vs-timestamp-comparing-oracle-date-and-timestamp-datatypes/"><strong>timestamp </strong></a>types and the formatting <a href="http://plsql.globinch.com/category/functions/"><strong>functions </strong></a>could be the most used functions of pl/sql.<span class="fullpost"> </span></p>
<p>The standard Oracle date format is <span style="font-weight: bold; color: #009900;">&#8216;DD-MON-YY&#8217;</span> for example &#8216;13-Nov-08&#8242;.</p>
<p><span style="font-weight: bold; color: #6600cc; font-style: italic;">How to change  this default date format for an oracle instance ?</span></p>
<p><span style="font-weight: bold;">NLS_DATE_FORMAT </span>specifies the default date format to use with the TO_CHAR and TO_DATE functions.<br />
This is specified oin the in the parameter file(<span style="font-weight: bold;">init.ora)</span>.</p>
<p><span style="font-style: italic; color: #3333ff;">For example</span><br />
NLS_DATE_FORMAT = &#8220;MM/DD/YYYY&#8221;</p>
<p>The default value of this parameter is determined by NLS_TERRITORY.<br />
During a user session user can change this with the <span style="font-weight: bold; color: #009900;">ALTER SESSION</span> statement.</p>
<p><span style="font-style: italic; color: #3333ff;">For example</span></p>
<pre class="brush: css;">

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS'
</pre>
<p><span style="font-weight: bold; font-style: italic; color: #6600cc;">How to enter  dates that are not in standard Oracle date format?</span></p>
<p>Use the TO_DATE function with a format mask,For example</p>
<pre class="brush: css;">
SQL&gt; select unique TO_DATE ('November 13, 1992', 'MONTH DD, YYYY') mydate from tab;
MYDATE
11/13/1992
SQL&gt;
</pre>
<p><span style="font-weight: bold; font-style: italic; color: #999900;">Related Topics,</span><br />
<a href="http://plsql.globinch.com/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma&#8230;</a></p>
<p><span style="font-weight: bold; font-style: italic; color: #3333ff;">Also Read,</span></p>
<ul>
<li><strong> </strong><a href="http://plsql.globinch.com/2008/11/05/database-schema-oracle-schema-objects-what-is-database-schema/"><strong>Database Schema | Oracle Schema Objects | What is database schema?</strong></a></li>
<li><a href="../2008/11/04/autonomous-transactions-in-plsql/"><strong>Autonomous Transactions in PL/SQL</strong></a></li>
<li><a href="../2008/11/05/2008/11/04/sql-transaction-statements-transaction-management/">SQL – Transaction Statements -Transaction Manageme…</a></li>
</ul>
<ul>
<li><a href="../2008/11/05/2008/11/04/2008/11/04/savepoints-in-sql-transactions-savepoint/"><strong>Savepoints In SQL Transactions. – SAVEPOINT</strong></a></li>
<li><a href="../2008/11/05/2008/11/04/2008/11/04/2008/10/31/oracle-tablespace-and-datafiles-introduction/">Oracle Tablespace, and Datafiles – Introduction</a></li>
<li><a href="../2008/11/05/2008/11/04/2008/11/04/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/">Formatting date in SQL (Oracle) -Simple date forma…</a></li>
<li><a href="../2008/11/05/2008/11/04/2008/11/04/2008/10/28/finding-database-objects-finding-valid-and-invalid-objects-and-finding-object-counts-sql-tips/">FINDING database objects, finding valid and INVALI…</a></li>
<li><a href="../2008/11/05/2008/11/04/2008/11/04/2007/06/05/oracle-data-types/">Oracle  Data types</a></li>
</ul>
<p style="text-align: right; font-size: 9px;">Technorati Tags:<br />
<a title="Link to Technorati Tag category for DATE Datatype in Oracle|Oracle Dates and Times|Dates in Oracle" rel="tag" href="http://www.technorati.com/tag/DATE+Datatype+in+Oracle%7COracle+Dates+and+Times%7CDates+in+Oracle" target="_blank">DATE Datatype in Oracle|Oracle Dates and Times|Dates in Oracle</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Formatting date in SQL (Oracle) -Simple date formatting</title>
		<link>http://plsql.globinch.com/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/</link>
		<comments>http://plsql.globinch.com/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 11:14:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Tips]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=9</guid>
		<description><![CDATA[Formatting date in SQL (Oracle) -Simple date formatting.Here is few simple SQL date formatting examples that can be useful while displaying dates in different formats.There are a number of formatting techniques available for dates and timestamps.
]]></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 = "Formatting date in SQL (Oracle) -Simple date formatting";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/";
		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%2F10%2F28%2Fformatting-date-in-sql-oracle-simple-date-formatting%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2008%2F10%2F28%2Fformatting-date-in-sql-oracle-simple-date-formatting%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Here is few simple <span style="font-weight: bold; color: #ff0000;">SQL </span>date formatting examples that can be useful while displaying dates in different formats.There are a number of formatting techniques available for dates and timestamps.<span class="fullpost"><br />
<span style="text-decoration: underline;"><span style="font-weight: bold; color: #009900;">1. DD:MONTH:YYYY HH24:MI:SS format</span><br />
</span></span></p>
<pre class="brush: css;">
SQL&gt; select distinct to_char(sysdate,'DD:MONTH:YYYY hh12:MI:ss') TIME_NOW from tab;

TIME_NOW
28:OCTOBER  :2008 04:37:12
</pre>
<p><span style="text-decoration: underline;"><span style="font-weight: bold; color: #009900;">2. Year in strings </span><br />
</span></p>
<pre class="brush: css;">
SQ&gt; select distinct to_char(sysdate,'DD-MONTH-YEAR hh12:mm:ss') today from tab;
TODAY
28-OCTOBER  -TWO THOUSAND EIGHT 04:10:40
</pre>
<p><span style="text-decoration: underline;"><span style="font-weight: bold; color: #009900;">3. Day and date as string </span><br />
</span></p>
<pre class="brush: css;">
SQL&gt; select distinct to_char(sysdate,'DAY DD--MONTH--YEAR hh12:mm:ss') today from tab;
TODAY
TUESDAY   28--OCTOBER  --TWO THOUSAND EIGHT 04:10:09
</pre>
<p><span style="color: #6666cc;"><span style="color: #3333ff; font-style: italic;">Related articles on oracle  DATE , TIMESTAMP etc</span></span></p>
<ul>
<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>
<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 Models</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 DATE vs TIMESTAMP |Comparing Oracle DATE and TIMESTAMP Datatypes</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/">Oracle to_char function and usage</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/">Using oracle date format |Using the DATE Format Mask in 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/">Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql</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/">ORA-01882: TIMEZONE REGION NOT FOUND |Oracle Error</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/">PL/SQL EXTRACT function for oracle datetime</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 Dates and Times |SYSDATE|CURRENT_TIMESTAMP |SYSTIMESTAMP |DBTIMEZONE |LOCALTIMESTAMP</a></li>
<li> <a title="Permalink to DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle" rel="bookmark" href="../2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/">oracle to_date | Oracle/PLSQL: To_Date Function</a></li>
<li> <a title="Permalink to DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle" rel="bookmark" href="../2008/11/13/date-data-type-in-oracleoracle-dates-and-timesdates-in-oracle/">oracle date difference | date difference in sql and PL/SQL</a></li>
<li> <a title="Permalink to Oracle Max(Date) function usage-SQL max date" rel="bookmark" href="../2008/12/04/oracle-maxdate-sql-max-date/">DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle</a></li>
<li> <a title="Permalink to Oracle Max(Date) function usage-SQL max date" rel="bookmark" href="../2008/12/04/oracle-maxdate-sql-max-date/">Oracle Max(Date) function usage-SQL max date</a></li>
</ul>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2008/10/28/formatting-date-in-sql-oracle-simple-date-formatting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oracle Data types</title>
		<link>http://plsql.globinch.com/2007/06/05/oracle-data-types/</link>
		<comments>http://plsql.globinch.com/2007/06/05/oracle-data-types/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 13:59:00 +0000</pubDate>
		<dc:creator>globinch-sql-plsql</dc:creator>
				<category><![CDATA[Data types]]></category>

		<guid isPermaLink="false">http://plsql.globinch.com/?p=5</guid>
		<description><![CDATA[
		
		
		
		 
			
				
			
		
Datatypes



Every constant and variable has a data type ,which  specifies the storage format. It also specifies the constraints ad valid range  of values.We can generalize the different types as followsscalar type :This type has no internal components.composite :This type has internal components that can be  manipulated individually.reference :This type  holds [...]]]></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 Data types";
		yahooBuzzArticleCategory = "";
		yahooBuzzArticleType = "text";
		yahooBuzzArticleId = "http://plsql.globinch.com/2007/06/05/oracle-data-types/";
		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%2F2007%2F06%2F05%2Foracle-data-types%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fplsql.globinch.com%2F2007%2F06%2F05%2Foracle-data-types%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<h4 align="center"><span style="color: rgb(128, 0, 128);font-size:100%;" >Datatypes</span></h4>
</td>
</tr>
<tr>
<td height="476" width="100%">Every constant and variable has a data type ,which  specifies the storage format. It also specifies the constraints ad valid range  of values.<br />We can generalize the different types as follows<br /><i><span style="color: rgb(0, 0, 255);">scalar type</span> :This type has no internal components.<br /><span style="color: rgb(0, 0, 255);">composite</span> :This type has internal components that can be  manipulated individually.<br /><span style="color: rgb(0, 0, 255);">reference</span> :This type  holds  pointers, that designate other program items.</i><em class="Italic"><br /><span style="color: rgb(0, 0, 255);">LOB</span> :This type holds values called  lob locators, that specify the location of large objects<br /></em> <span class="fullpost"><br />
<table border="0" height="540" width="100%">
<tbody>
<tr>
<td height="19" width="100%">
<table bordercolordark="#ff0000" bordercolorlight="#008000" style="color: rgb(255, 0, 255);" border="2" height="440" width="100%">
<tbody>
<tr>
<td height="19" width="13%"><b><span style="color: rgb(0, 0, 255);">Scalar type</span></b></td>
<td height="19" width="20%"><span style="color: rgb(0, 0, 255);">Subtypes</span></td>
<td height="19" width="17%"><b><span style="color: rgb(0, 0, 255);">Composite type</span></b></td>
<td height="19" width="25%"><b><span style="color: rgb(0, 0, 255);">Reference type</span></b></td>
<td height="19" width="25%"><b><span style="color: rgb(0, 0, 255);">LOB type</span></b></td>
</tr>
<tr>
<td rowspan="5" height="80" width="13%"><span style="color: rgb(128, 0, 128);">BINARY_INTEGER</span></td>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >NATURAL</span></td>
<td style="text-align: justify;" rowspan="22" height="394" valign="top" width="17%"><span style="color: rgb(128, 0, 128);">RECORD<br />TABLE<br />VARRAY</span></td>
<td rowspan="22" height="394" valign="top" width="25%"><span style="color: rgb(128, 0, 128);">REF  CURSOR<br />REF object_Type</span></td>
<td rowspan="22" height="394" valign="top" width="25%"><span style="color: rgb(128, 0, 128);">BFILE<br />BLOB<br />CLOB<br />NCLOB</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >POSITIVE</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >NATURALN</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >POSITIVEN</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >SIGNTYPE</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >PLS_INTEGER</span></td>
</tr>
<tr>
<td rowspan="10" height="160" width="13%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >NUMBER</span></td>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >INT</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >INTEGER</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >SMALLINT</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >DEC</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >DECIMAL</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >NUMERIC</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >DOUBLE  PRECISION</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >FLOAT</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >BINARY_DOUBLE</span></td>
</tr>
<tr>
<td height="16" width="20%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >BINARY_FLOAT</span></td>
</tr>
<tr>
<td height="16" width="17%"><span style="color: rgb(128, 0, 128);font-family:Arial;font-size:85%;"  >CHAR</span></td>
<td height="16" width="16%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >CHARACTER</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >NCHAR</span></td>
</tr>
<tr>
<td rowspan="2" height="32" width="17%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >VARCHAR2</span></td>
<td height="16" width="16%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >STRING</span></td>
</tr>
<tr>
<td height="16" width="16%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >VARCHAR</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >NVARCHAR2</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="color: rgb(128, 0, 128);font-family:Courier;" >RAW</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="font-family:Courier;">ROWID</span></td>
</tr>
<tr>
<td colspan="2" height="1" width="33%"><span style="font-family:Courier;">UROWID</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="font-family:Courier;">BOOLEAN</span></td>
</tr>
<tr>
<td colspan="2" height="16" width="33%"><span style="font-family:Courier;">DATE</span></td>
</tr>
</tbody>
</table>
<p></span></td>
</tr>
<tr>
<td height="21" width="100%">
<table border="1" height="1012" width="100%">
<tbody>
<tr>
<td height="19" width="33%"><b><span style="color: rgb(128, 0, 128);">Data type  defintion</span></b></td>
<td height="19" width="33%"><b><span style="color: rgb(128, 0, 128);">PL/SQL</span></b></td>
<td height="19" width="34%"><b><span style="color: rgb(128, 0, 128);">SQL</span></b></td>
</tr>
<tr>
<td height="19" width="33%">CHAR(<chars>) </chars></td>
<td height="19" width="33%">32,767 chars </td>
<td height="19" width="34%">2,000 chars</td>
</tr>
<tr>
<td height="19" width="33%">NCHAR(<bytes>)</bytes></td>
<td height="19" width="33%">32,767 bytes</td>
<td height="19" width="34%">2,000 bytes</td>
</tr>
<tr>
<td height="19" width="33%">LONG </td>
<td height="19" width="33%">32,760 bytes</td>
<td height="19" width="34%">2GB</td>
</tr>
<tr>
<td height="19" width="33%">VARCHAR2(<chars>)</chars></td>
<td height="19" width="33%"> 32,767 chars</td>
<td height="19" width="34%"> 4,000 chars</td>
</tr>
<tr>
<td height="19" width="33%">NVARCHAR2(<bytes>)</bytes></td>
<td height="19" width="33%">32,767 bytes</td>
<td height="19" width="34%"> 4,000 bytes</td>
</tr>
<tr>
<td height="19" width="33%">CHARACTER</td>
<td height="19" width="33%">2,000 chars</td>
<td height="19" width="34%">2,000 chars</td>
</tr>
<tr>
<td height="19" width="33%">STRING(<chars>)</chars></td>
<td height="19" width="33%">32,767 bytes</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td height="19" width="33%">VARCHAR </td>
<td height="19" width="33%">32,767 bytes</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Integer</i></b></td>
</tr>
<tr>
<td height="37" width="33%">BINARY_INTEGER<br />(same as PLS_INTEGER in 10g)</td>
<td height="37" width="33%">32 bit </td>
<td height="37" width="34%">N/A</td>
</tr>
<tr>
<td height="19" width="33%">PLS_INTEGER</td>
<td height="19" width="33%">32 bit </td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Floating Point</i></b></td>
</tr>
<tr>
<td height="19" width="33%">NUMBER </td>
<td height="19" width="33%">38 chars</td>
<td height="19" width="34%">38 chars</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Fixed Point</i></b></td>
</tr>
<tr>
<td height="19" width="33%">NUMBER(
<precision>,<scale>)</scale></precision></td>
<td height="19" width="33%">38 chars</td>
<td height="19" width="34%">38 chars</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Non-negative  Integers</i></b></td>
</tr>
<tr>
<td height="19" width="33%">NATURAL </td>
<td height="19" width="33%">32 bit</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td height="19" width="33%">POSITIVE </td>
<td height="19" width="33%">32 bit</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Not Nullable Non-negative  Integers</i></b></td>
</tr>
<tr>
<td height="19" width="33%">NATURALN </td>
<td height="19" width="33%">32 bit</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td height="19" width="33%">POSITIVEN </td>
<td height="19" width="33%">32 bit</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Restricted</i></b></td>
</tr>
<tr>
<td height="19" width="33%">SIGNTYPE </td>
<td height="19" width="33%">-1, 0, +1</td>
<td height="19" width="34%">N/A</td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><i><b>Integers with up to 38 decimal  digits</b></i></td>
</tr>
<tr>
<td height="19" width="33%">INT </td>
<td height="19" width="33%">38</td>
<td height="19" width="34%">38</td>
</tr>
<tr>
<td height="19" width="33%">INTEGER </td>
<td height="19" width="33%">38 </td>
<td height="19" width="34%">38</td>
</tr>
<tr>
<td height="19" width="33%">SMALLINT </td>
<td height="19" width="33%">38 </td>
<td height="19" width="34%">38 </td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Fixed point numbers up to 38 decimal  digits</i></b></td>
</tr>
<tr>
<td height="19" width="33%">DEC(
<precision>,<scale>) </scale></precision></td>
<td height="19" width="33%">38 </td>
<td height="19" width="34%">38 </td>
</tr>
<tr>
<td height="19" width="33%">DECIMAL(
<precision>,<scale>) </scale></precision></td>
<td height="19" width="33%">38 </td>
<td height="19" width="34%">38 </td>
</tr>
<tr>
<td height="19" width="33%">NUMERIC(
<precision>,<scale>)</scale></precision></td>
<td height="19" width="33%">38 </td>
<td height="19" width="34%">38 </td>
</tr>
<tr>
<td colspan="3" height="19" width="100%"><b><i>Floating point numbers up to 126  binary digits</i></b></td>
</tr>
<tr>
<td height="19" width="33%">DOUBLE PRECISION(<bin.>) </bin.></td>
<td height="19" width="33%">126 </td>
<td height="19" width="34%">126 </td>
</tr>
<tr>
<td height="19" width="33%">FLOAT(<bin.>)</bin.></td>
<td height="19" width="33%">126 </td>
<td height="19" width="34%">126 </td>
</tr>
<tr>
<td height="19" width="33%">REAL </td>
<td height="19" width="33%">63 bin.digits</td>
<td height="19" width="34%">63 bin.digits</td>
</tr>
<tr>
<td colspan="3" height="38" width="100%"><b><i>Floating point numbers using native  machine arithmetic</i></b></td>
</tr>
<tr>
<td height="19" width="33%">BINARY_DOUBLE </td>
<td height="19" width="33%">64 bit </td>
<td height="19" width="34%">64 bit </td>
</tr>
<tr>
<td height="19" width="33%">BINARY_FLOAT </td>
<td height="19" width="33%">32 bit</td>
<td height="19" width="34%">32 bit</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></span></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://plsql.globinch.com/2007/06/05/oracle-data-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

