Is there a function built into Oracle that will return the highest possible date that may be inserted into a date field?
Asked
Active
Viewed 6.3k times
27
-
5Why ? If you start putting in dummy 'high-date' values into a table, it can 'confuse' the optimizer which will assume that you have a whole range of date values spread over the next 8 thousand years. – Gary Myers Mar 27 '09 at 09:30
5 Answers
36
SELECT TO_DATE('31.12.9999 23:59:59', 'dd.mm.yyyy hh24:mi:ss')
FROM dual
Note that minimal date is much more simple:
SELECT TO_DATE(1, 'J')
FROM dual

Quassnoi
- 413,100
- 91
- 616
- 614
-
14I think for most people's purposes `TO_DATE('9999', 'yyyy')` would be a much shorter and acceptable alternative, especially when using to coalesce nulls in comparisons. – Alex Apr 17 '12 at 16:18
-
2
-
1
-
2`TO_DATE(1, 'J')` returns 1st of January, the current year for me? – Richard Dingwall Apr 20 '12 at 12:56
-
@RichardDingwall: for everyone else, it does not. http://www.sqlfiddle.com/#!4/8ce59/2 – Quassnoi Apr 20 '12 at 12:58
-
2TO_DATE(1, 'J') returned January, 01 4713 00:00:00-0800 for me in sqlfiddle – Partha Choudhury Aug 16 '12 at 20:59
-
1`SELECT to_char(TO_DATE('31.12.9999 23:59:59', 'dd.mm.yyyy hh24:mi:ss'), 'J') FROM dual;` would give `5373484`. Hence the second query should be `SELECT to_date(5373484, 'J') FROM dual;`. – Lalit Kumar B Feb 13 '15 at 05:13
-
-
@Quassnoi, completely missed it, apologies. I need a coffee break. I never expected a completely opposite solution. Question is about maximum date value, so why did you provide an opposite solution? Jusr curious. – Lalit Kumar B Feb 13 '15 at 16:05
-
8
From the 11g docs:
Oracle Database can store dates in the Julian era, ranging from January 1, 4712 BCE through December 31, 9999 CE (Common Era, or 'AD').
http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/datatype.htm#i1847

Angelo Marcotullio
- 801
- 6
- 6
-
4Common Era... Is that a politically correct term for the "confessionally biased" AD ? – Thilo Mar 27 '09 at 08:37
-
2
I do not know of a function but according to this article:
Oracle 7: from January 1, 4712 BC to December 31, 4712 AD.
Oracle 8: from January 1, 4712 BC to December 31, 9999 AD.
Oracle 9: from January 1, 4712 BC to December 31, 9999 AD.
PL/SQL: from January 1, 4712 BC to December 31, 9999 AD.

Andrew Hare
- 344,730
- 71
- 640
- 635
2
Another ways, just for fun:
SELECT to_date(5373484, 'J') + (1 - 1/24/60/60)
FROM dual;
SELECT date '9999-12-31' + (1 - 1/24/60/60)
FROM dual;

Lalit Kumar B
- 47,486
- 13
- 97
- 124

FerranB
- 35,683
- 18
- 66
- 85
-
The first query should be `SELECT to_date(5373484, 'J') + (1 - 1/24/60/60) FROM dual;` – Lalit Kumar B Feb 13 '15 at 05:18