Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Oracle / Oracle Server / December 2005

Tip: Looking for answers? Try searching our database.

Regarding date formats

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Giridhar - 30 Dec 2005 11:11 GMT
Hi,
Please review the following two pl/sql blocks.
Our NLS_DATE_FORMAT is defined as DD-MON-RR.
------------------------------------------------------------
SQL> declare
 2  v date;
 3  begin
 4  select decode(0,-1,NULL,(to_date('05251932', 'MMDDYYYY'))) into v
from
dual;
 5  DBMS_OUTPUT.PUT_LINE(to_char(v,'DD-MON-YYYY'));
 6  end;
 7  /
-----------
25-MAY-2032
-----------
PL/SQL procedure successfully completed.

SQL> declare
 2  v date;
 3  begin
 4  select to_date('05251932', 'MMDDYYYY') into v from dual;
 5  DBMS_OUTPUT.PUT_LINE(to_char(v,'DD-MON-YYYY'));
 6  end;
 7  /
-----------
25-MAY-1932
-----------
PL/SQL procedure successfully completed.
------------------------------------------------------------

May i know why the first one is displaying value as 25-MAY-2032 instead
of
25-MAY-1932

Thanks
Giridhar
Frank van Bortel - 30 Dec 2005 11:40 GMT
> Hi,
> Please review the following two pl/sql blocks.
[quoted text clipped - 33 lines]
> Thanks
> Giridhar

Because you have a decode, and that does (datatype) conversions.
"Oracle7 automatically converts the return value to the same
datatype as the first result."
Your first result is -1, the outcome of the decode would therefore
become numeric. As your assignment datatype is date, a conversion
will take place, and that will go through a varchar2. As this is
an implicit conversion, the default date format mask is applied,
"DD-MON-RR".

As case statement would prevent this, but isn't available in Oracle7.
Signature

Regards,
Frank van Bortel

Top-posting is one way to shut me up...

Michel Cadot - 30 Dec 2005 12:14 GMT
| > Hi,
| > Please review the following two pl/sql blocks.
[quoted text clipped - 44 lines]
|
| As case statement would prevent this, but isn't available in Oracle7.

The first result is NULL (not -1) which is of VARCHAR2 datatype.
This does not change the rest of your post: date->varchar2->date conversion
and the application of implicit date format.

Regards
Michel Cadot
Giridhar - 30 Dec 2005 12:53 GMT
Thanks for your replies. I forgot to mention that i am using Oracle9i
Enterprise Edition Release 9.2.0.5.0.

Regards,
Giridhar
Frank van Bortel - 30 Dec 2005 13:49 GMT
> | Because you have a decode, and that does (datatype) conversions.
> | "Oracle7 automatically converts the return value to the same
[quoted text clipped - 13 lines]
> Regards
> Michel Cadot

You are correct; here's the relevant bit, copy/pasted from
the 9i SQL Reference Manual (and not wrongly interpreted
from the 7.3 printed manual):
"Oracle automatically converts the return
value to the same datatype as the first result.
If the first result has the datatype CHAR or
if the first result is null, then Oracle converts
the return value to the datatype VARCHAR2."

Signature

Regards,
Frank van Bortel

Top-posting is one way to shut me up...

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.