34 lines
1.3 KiB
Plaintext
34 lines
1.3 KiB
Plaintext
The ``++TO_DATE++`` and ``++TO_TIMESTAMP++`` functions are converting char of ``++CHAR++``, ``++VARCHAR2++``, ``++NCHAR++``, or ``++NVARCHAR2++`` datatype to respectively a value of ``++DATE++`` or ``++TIMESTAMP++`` datatype.
|
|
|
|
Without providing the format of the input char, ``++TO_DATE++`` will consider the provided char is compliant with the default date format. Relying on a default configuration is a source of error because it creates a dependency between the code and the configuration of the ORACLE server where this code is deployed.
|
|
|
|
According to the Oracle's documentation "the default date format is determined implicitly by the NLS_TERRITORY initialization parameter or can be set explicitly by the NLS_DATE_FORMAT parameter.". It means the behaviour of the ``++TO_DATE++`` function will certainly not be the expected one if the configuration of the ORACLE server is changing.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,sql]
|
|
----
|
|
SELECT TO_DATE( 'January 15, 2018, 11:00 A.M.')
|
|
FROM DUAL;
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,sql]
|
|
----
|
|
SELECT TO_DATE( 'January 15, 2018, 11:00 A.M.', 'Month dd, YYYY, HH:MI A.M.')
|
|
FROM DUAL;
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|