Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Dates: Oddball Stuff Jump to:  
Category: >> Oracle PL/SQL >> Dates: Oddball Stuff Bookmark and Share

<< lastnext >>

Snippet Name: Dates: Oddball Stuff

Description: ANSI date-time datatypes and arithmetic can make life difficult and perplexing for the programmer. Notice some of these "gotchas".

Also see:
» ANSI Joins: FULL JOIN
» ANSI Joins: OUTER JOIN
» ANSI Joins: CROSS JOIN
» ANSI Joins: INNER JOIN

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 10th, 2009

ALTER session SET nls_date_format = 'YYYY-MM-DD';
 
-- old 
SELECT ADD_MONTHS(TO_DATE('2003-07-31','YYYY-MM-DD'),-1) FROM dual;
 
ADD_MONTHS
----------
2003-06-30
 
-- new
SELECT TO_TIMESTAMP('2003-07-31','YYYY-MM-DD') - INTERVAL '1' MONTH FROM dual;
 
ERROR AT line 1:
ORA-01839: DATE NOT valid FOR MONTH specified
 
-- old 
SELECT TO_DATE('2003-07-31','YYYY-MM-DD') - 100 FROM dual;
 
-- new (broken)
SELECT TO_TIMESTAMP('2003-07-31','YYYY-MM-DD') - INTERVAL '100' DAY FROM dual;
 
ERROR AT line 1:
ORA-01873: the leading precision OF the INTERVAL IS too small
 
-- new (note the extra "(3)")
SELECT TO_TIMESTAMP('2003-07-31','YYYY-MM-DD') - INTERVAL '100' DAY(3) FROM dual;
 
TO_TIMESTAMP('2003-07-31','YYYY-MM-DD')-INTERVAL'100'DAY(3)
-------------------------------------------------------------
2003-04-22 00:00:00
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 285 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?