0

What is the difference between next two query in Oracle DB (11g Enterprise Edition Release 11.2.0.1.0):

SELECT DATE '2018-02-01'  FROM DUAL;

and

SELECT DATE('2018-02-01') FROM DUAL;

Where the first one work fine, but the next one I get next error:

ORA-00936: missing expression

Thanks BR

2
  • 2
    There is no function date() - you probably want to_date() Commented Feb 1, 2018 at 8:44
  • The same difference that between N'foo' and N('foo'). Not everything that has parenthesis is a function call, but all function calls need parenthesis. Commented Feb 1, 2018 at 8:50

1 Answer 1

2

From Oracle docs:

You can specify a DATE value as a string literal, or you can convert a character or numeric value to a date value with the TO_DATE function. DATE literals are the only case in which Oracle Database accepts a TO_DATE expression in place of a string literal. To specify a DATE value as a literal, you must use the Gregorian calendar. You can specify an ANSI literal, as shown in this example:

DATE '1998-12-25'

The ANSI date literal contains no time portion, and must be specified in the format 'YYYY-MM-DD'. Alternatively you can specify an Oracle date value, as in the following example:

TO_DATE('98-DEC-25 17:30','YY-MON-DD HH24:MI')

Please notice that, according to Wernfried Domscheit, using only 2 digits for years is not a great idea. If you want to use a to_date, you would better use a 4-digit format:

TO_DATE('1998-DEC-25 17:30','YYYY-MON-DD HH24:MI')
Sign up to request clarification or add additional context in comments.

2 Comments

Using only 2 digits for year is not very smart. Your example is the best proof - did you like to get 2098-12-25 rather than 1998-12-25?
@WernfriedDomscheit: It's from Oracle documentation :). Edited to clarify, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.