When a DATE value is displayed, Oracle must first convert that value from the special internal format to a printable string. The conversion is done by a function TO_CHAR, according to a DATE format. Oracle's default format for DATE is "DD-MON-YY". Therefore, when you issue the query
select b from x;
you will see something like:
B
---------
01-APR-98
Whenever a DATE value is displayed, Oracle will call TO_CHAR automatically with the default DATE format. However, you may override the default behavior by calling TO_CHAR explicitly with your own DATE format. For example,
where the <format> string can be formed from over 40 options. Some of the more popular ones include:
MM
Numeric month (e.g., 07)
MON
Abbreviated month name (e.g., JUL)
MONTH
Full month name (e.g., JULY)
DD
Day of month (e.g., 24)
DY
Abbreviated name of day (e.g., FRI)
YYYY
4-digit year (e.g., 1998)
YY
Last 2 digits of the year (e.g., 98)
RR
Like YY, but the two digits are ``rounded'' to a year in the range 1950 to 2049. Thus, 06 is considered 2006 instead of 1906, for example.
AM (or PM)
Meridian indicator
HH
Hour of day (1-12)
HH24
Hour of day (0-23)
MI
Minute (0-59)
SS
Second (0-59)
You have just learned how to output a DATE value using TO_CHAR. Now what about inputting a DATE value? This is done through a function called TO_DATE, which converts a string to a DATE value, again according to the DATE format. Normally, you do not have to call TO_DATE explicitly: Whenever Oracle expects a DATE value, it will automatically convert your input string using TO_DATE according to the default DATE format "DD-MON-YY". For example, to insert a tuple with a DATE attribute, you can simply type: