I want to update my date column for some purpose. The value already stored in the column is like below
18-06-14
and while updating If I don\'t updat
A date does not have a format - it is stored internally to the database as 7-bytes (representing year, month, day, hour, minute and second) and it is not until whatever user interface you are using (i.e. SQL/Plus, SQL Developer, Java, etc) tries to display it to you, the user, and converts it into something you would find meaningful (usually a string) that the date has a format.
If you are providing a formatted date to a procedure then it will be a string and Oracle will try to implicitly cast it to a date using the NLS_DATE_FORMAT
session parameter:
UPDATE your_table
SET your_date_column = '18-06-14'; -- or equivalently via a bind parameter
Is implicitly converted to
UPDATE your_table
SET your_date_column = TO_DATE(
'18-06-14',
( SELECT value
FROM NLS_SESSION_PARAMETERS
WHERE parameter = 'NLS_DATE_FORMAT' )
);
If the NLS_DATE_FORMAT
does not match then Oracle will raise an exception (and the parameter can be set by each user so you should not rely on it being consistent - especially in international organisations when the default date format depends on your territory and language).
If you are updating the value then use a DATE
literal and not a string:
UPDATE your_table
SET your_date_column = DATE '2014-06-18';
Or explicitly convert the string and provide the format model:
UPDATE your_table
SET your_date_column = TO_DATE( '18-06-14', 'DD-MM-RR' );
The same is true for passing parameters to your function. Either use a DATE
literal:
BEGIN
your_procedure(
p_launch_date => DATE '2014-06-18'
);
END;
/
or explicitly convert the string to a date (and do not rely on implicit conversion):
BEGIN
your_procedure(
p_launch_date => TO_DATE( '18-06-14', 'DD-MM-RR' )
);
END;
/