Oracle to_char function and usage

      1 Comment on Oracle to_char function and usage
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

A to_char function is useful while displaying oracle date value to a required string format.This is particularly useful for displaying the dates in the most suitable format required.Few examples of using this method with different formats given below.

See the below example for to_char function usage.

<pre>-- Created on 11/19/2008 by Globinch PLSQLTIPS
declare
-- Local variables here
test_Date DATE;

begin
  -- Initialize the date
   test_Date := to_date('12/12/2008','DD/MM/YYYY');
   --To display day and all other details
   dbms_output.put_line('The date :' || to_char(test_Date,'Dy DD-MM-YYYY HH24:MI:SS'));
   --To display month in text
   dbms_output.put_line('The date :' ||to_char(test_Date,'Dy DD-MON-YYYY HH24:MI:SS'));
   --To display 12HR format and milliseconds
  dbms_output.put_line('The date :' || to_char(sysdate,'YYYY/MM/DD HH12:MI:SS:ssss'));
  --To display AM/PM format
  dbms_output.put_line('The date :' || to_char(sysdate,'YYYY/MM/DD HH12:MI:SS:ssss AM '));

end;
/
The date :Fri 12-12-2008 00:00:00
The date :Fri 12-DEC-2008 00:00:00
The date :2008/11/19 03:29:15:1515

Read,

Technorati Tags:
, , , ,

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

1 thought on “Oracle to_char function and usage

  1. Pingback: Oracle DATE vs TIMESTAMP |Comparing Oracle DATE and TIMESTAMP Datatypes | SQL and PLSQL

Leave a Reply

Your email address will not be published. Required fields are marked *

Paged comment generated by AJAX Comment Page