what is the difference between to_char and to_date
functions?

Answer Posted / sushant butta

Check the answer in detail here. http://www.oraclebin.com/2012/12/what-is-difference-between-tochar-and.html

A lot of people have confusion about the usage of to_char and to_date functions. When to use to_char and when to use to_date. Here I am going to tell you how to do that. I will be discussing to_char function with respect to date only and not with numbers.

Syntax
to_char(value , format_mask)

to_date(string , format_mask)

So when you want to convert a date to a string use to_char function. Always remember that INPUT to to_char function is always a date (excluding numbers here). A format mask over here decides how OUTPUT of to_char function will look. Lets consider this with an example.



sql > Select to_char(sysdate,'DD-MM-YYYY') from dual;

Output : 01-01-2001

INPUT -> sysdate ( a date)
OUTPUT -> 01-01-2001 ( DD-MM-YYYY the format mask)

And when you want to convert a string to a date use to_date function. Always remember that OUTPUT of to_date function is always a date. A format mask over here decides what will the format of INPUT string. Lets have an example.

sql > select to_date( '01-01-2001','DD-MM-YYYY') from dual;

Output : 01-JAN-01

INPUT -> 01-01-2001 ( format_mask is 'DD-MM-YYYY')
OUTPUT -> 01-JAN-01 ( a date, the format here is the default NLS setting for your date)


Just remember the input and output of these functions and you will never make a mistake.

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are actual parameters and formal parameters?

570


Why do we use joins in sql?

502


What does sql stand for?

546


How does a self join work?

520


What is number function in sql?

527






column A column b | output 10 7 | 10 5 8 | 8 7 -9 | 7 3 5 | 5 0 6 | 6 Write a sql query to print such output.

6084


What is left join example?

504


What are different categories of sql commands?

634


Why triggers are used?

557


What are the packages in pl sql?

575


What is right join in sql?

555


what is self-join? : Sql dba

571


what are null values? : Sql dba

544


What is a full join sql?

593


What are the different tcl commands in sql?

620