Have some dates in my local Oracle 11g database that are in this format:
01-JUL-85
How do I change it to this format (mm/dd/yyyy) using PL/SQL:
7/01/1985
With thanks...
If the column is a date datatype then it is only your NLS_DATE settings that are causing them to be displayed in the format DD-MON-YYYY.
To check your current NLS_DATE format run the following:
SELECT value
FROM V$NLS_Parameters
WHERE parameter ='NLS_DATE_FORMAT';
Oracle stores all dates in an internal binary format and uses the NLS_DATE format to display them (unless explicitly told to display them differently).
You can either alter your NLS_DATE settings to MM/DD/YYYY or TO_CHAR the date column using:
TO_CHAR(<date_column>, 'MM/DD/YYYY')
to see the format you require.
You can alter the NLS_DATE format for your current session or alter the database parameters to change the default NLS_DATE format for the database itself.
If the column is a VARCHAR2 type then you'll need to convert to a date first and then you can format the output using either of the methods described above.
See: http://ss64.com/ora/syntax-nls.html
and: http://www.dba-oracle.com/t_nls_date_format_sysdate.htm
e.g.
SELECT TO_CHAR(sysdate, 'MM/DD/YYYY') as current_date
FROM dual;
or
ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY';
SELECT sysdate
FROM dual;
In pure PL/SQL
DECLARE
v_date DATE := sysdate;
BEGIN
DBMS_OUTPUT.put_line(TO_CHAR(v_date, 'MM/DD/YYYY'));
END;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With