Oracle DATE constant expression invariant to date format settings

0
=
0
+
0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

How to include a DATE constant / expression / literal in my PL/SQL script so the script would successfully run in different database environments with potentially different default date format settings? I am referring here to NLS settings, specifically NLS_DATE_FORMAT

Tags: ,

1 Answer

1
=
0
=
$0
Internet users could send Bitcoin Tips to you if they like your answer!

I think the easiest is to use string literal encoding your date, together with the explicit date format to be used in conversion from your string to date

-- Dec 25, 2010
select to_date('20101225','YYYYMMDD') from dual;

-- DD means Day of month (1-31), so both statements below would produce Dec 1, 2010
-- note that MM does not have that ambiguity and must always be (01-12) with the LEADING ZERO
select to_date('20101201','YYYYMMDD') from dual;
select to_date('2010121','YYYYMMDD') from dual;
SEND BITCOIN TIPS
1

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer