0% found this document useful (0 votes)
26 views1 page

To_Char and To_Date Functions Guide

The document outlines the usage of the To_Char and To_Date functions in SQL for formatting dates and numbers in the 'airlines' table. It provides examples of how to add columns, update values, and select formatted outputs for hire dates and salaries. Additionally, it demonstrates converting string representations of dates into date objects using the To_Date function.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

To_Char and To_Date Functions Guide

The document outlines the usage of the To_Char and To_Date functions in SQL for formatting dates and numbers in the 'airlines' table. It provides examples of how to add columns, update values, and select formatted outputs for hire dates and salaries. Additionally, it demonstrates converting string representations of dates into date objects using the To_Date function.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Character conversion Functions

(A) USage of To_Char


function with dates
1) add column hire_date in any table
Example ------->>>>alter table airlines add hire_date Date;

2) Update the column values


Example ------->>>> update airlines set hire_date='17-OCT-2017';

Execution of functions
1) select To_char(hire_date,'MM/YY') from airlines;
2) select To_char(hire_date,'fmDD Month YYYY') as Month_HIred from airlines;
3) select To_char(hire_date,'fmDdspth "of" Month YYYY fmHH:MI:SS AM') as
Month_HIred from airlines;

(B) USage of To_Char function


with numbers
alter table airlines add sal number;
update airlines set sal=5000;
select To_char(sal,'$99,999.00') as Month_HIred from airlines;
select To_char(sal,'99,999') as Month_HIred from airlines;
select To_char(sal,'099999') as Month_HIred from airlines;
select To_char(sal,'9999D99') as Month_HIred from airlines;
select To_char(sal,'9G999') as Month_HIred from airlines;
select To_char(sal,'999,999') as Month_HIred from airlines;

(C) Usage of To_Date


function
1)
alter table airlines add hdate varchar(255);

update airlines set hdate='17 October,2017';

select To_date('17 October,2017','DD fxMonth,YYYY') from airlines;

You might also like