what is the difference between to_char and to_date
functions?
Answers were Sorted based on User's Feedback
Answer / rajesh
to_char function is used to convert the given data into
character....
eg:to_char(sysdate,'month') which returns month alone...
to_date is used to convert the given data into date data
formate data type....
eg: to_date('070903', 'MMDDYY') would return a date value
of July 9, 2003.
Is This Answer Correct ? | 137 Yes | 33 No |
Answer / jacob
try this out
select to_char(sysdate,' Day "," DDsp"th " Month Year') from
dual
this gives the day,date,month,year of the current date
Is This Answer Correct ? | 43 Yes | 15 No |
Answer / kushal
to_char is used to convert dates into a character
representation, for example, if you want your query to
format the date differently:
i.e.
SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') FROM
dual; --> 09/06/2004 12:57:54
SELECT TO_CHAR(SYSDATE, 'Day ddth Month') FROM
dual; --> Wednesday 09th June
The to_date function is used when you have character input,
but need it as a date object (for example when the database
column is a Date, you need to insert a date)
i.e.
SELECT TO_DATE('01/01/2004', 'DD/MM/YYYY') FROM dual
SELECT TO_DATE('01/01/2004 13:13:13', 'DD/MM/YYYY
HH24:MI:SS') FROM dual
@madhu:-sysdate bydefault gives the date in
dateformat,which is prerequisite of the to_char.
For other dates we have to convert first in date format and
then operate to_char accordingly to change the format as
needed for the date.
Is This Answer Correct ? | 31 Yes | 4 No |
Answer / sanjukata
to_char()is required to convert number type and date type
of value to character type.
try this
select ename,hiredate,to_char(hiredate,'day ddth mon yy')
from emp;
to_date()is required to convert charater type of value to
date type.
try this
select to_date('22092010','dd-mm-yy')from dual;
Is This Answer Correct ? | 15 Yes | 3 No |
Answer / naveen
to_char function is used to convert the given data into
character....
eg:to_char(sysdate,'month') which returns month alone...
to_date is used to convert the given data into date data
formate data type....
eg: to_date('070903', 'MMDDYY') would return a date value
of July 9, 2003.
Is This Answer Correct ? | 10 Yes | 0 No |
Answer / 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 |
Answer / madhu
The Simple examples is correct but we take the date in date
format not like sysdate or hiredate.
if u select to_char('some date') and to_date('somedate')
explain with this examples if any one know.
Is This Answer Correct ? | 7 Yes | 6 No |
Answer / m
to_char conversion function will convert given data to character data whereas to_data will convert given character data into date format model.
Also we can say like to_char conversion function use for convert invalid data into valid data.
and to_date conversion function will convert valid data into invalid.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / susan
To_char is to convert number or date(string format) to character format.
To_date is from character format to date,only fetches d data when dere s valid number..
Is This Answer Correct ? | 2 Yes | 5 No |
how do you know the version of your mysql server? : Sql dba
I have one table,in that table (1)i have java1.1 version books are 2 and java1.5 version books are 4. (2).Net2.0 books are 3, .Net3.5 books are 2 (3)ABC1.6 books are 4, ABC2.0 books are 3. Now i want output is like Book Count Java 6 .Net 5 ABC 7 For this i need sql query, please help me if anyone how to get this result. Thanks, Seenu
C. Normalize the following data up to the 3rd Normal form. Create the tables and insert the data given. Emp_ID Name Dept_Name Salary Course_Title Date_Completed 100 Adam Marketing 48,000 SPSS 6/19/2008 Surveys 10/7/2008 140 Bob Accounting 52,000 Tax Acc 12/8/2008 110 Cathy IT SQL Server 1/12/2008 C# 4/22/2008 190 Dan Finance 150 Emily Marketing 55,000 SPSS 6/16/2008 42,000 Analysis 8/12/2008 Queries 1. Find all Names who have completed the SPSS Course. 2. Find employee with max salary. 3. Find employee with 2nd max salary. 4. Find all employees in Dept “Marketing”. 5. Find all the employees who have taken more than 2 courses. 6. Find all the employees who have completed the courses before month of September.
Q1.all the depts which has more then 10 empls? Q2.all the dept which does not have any emply? Q3 all the emp which does not have any dept? Q4 get all the emply detais with the dept details it dept is exit otherwise any emp details? Q5 how to debugg the dynamic sql and packages?
Is time a data type in sql?
What is not null in sql?
How many null values can be inserted in a coulmn whihc is unique constraint
How do I create a memory optimized filegroup?
Why query optimization is needed?
What is sap sql anywhere?
what are string data types? : Sql dba
Explain constraints in sql?