Dates (stored in tables) are represented by 7 bytes - they do not have any format associated with them. If they are formatted as a string then that is the client program which you are using to access the database applying its own formatting to the date (which you can usually set via the preferences in that program).
If the "date" is stored with a format then you are not storing it as a date but storing it as a string (i.e. VARCHAR2
) format.
DATETOSTRING
is not an Oracle function - TO_CHAR( datevalue, format_model, nlsparams )
is an Oracle function.
I retrieved date from one table in a mm/dd/yyyy hh24:mi:ss format. Now I want to store it in another table in a dd-mon-rr format.
No, if you retrieved a DATE
then you got 7-bytes from the database - the user interface (i.e. SQL/Plus, SQL Developer, Java, etc.) you are using performed an implicit conversion to make those 7-bytes understandable to you, the user, when it displayed it.
SQL/Plus and SQL developer will use the NLS_DATE_FORMAT
, NLS_DATE_LANGUAGE
and NLS_TERRITORY
session parameters as the default format model and NLS parameters to the TO_CHAR
function to perform this implicit conversion - but these are per-user settings and should not be relied upon to be consistent across multiple users (especially in an international setting).
If you want to store a DATE
then it has NO format - if you then want to display it with a specific format then you will need to convert it from a DATE
to a string using TO_CHAR
with your desired format model.
So, you can simply use:
To copy the date from one table to another:
INSERT INTO efg (r_date)
SELECT r_date FROM abc;
To get the date in your desired format:
SELECT TO_CHAR( r_date, 'dd-mon-rr' ) AS r_date
FROM efg