Conversion functions:
Ø Conversion functions convert a value from one data type to another.
v TO_CHAR
v TO_DATE
v TO_NUMBER
To_Char conversion:
TO_CHAR()
function converts date value to a string in specified date format.
Syntax:
Explanation:
Ø Format_method
must be enclosed with the single quotes
Ø Format_method
should be Case sensitive.
Example:
EMPNO |
ENAME |
SAL |
HIREDATE |
1001 |
KING |
20000 |
10-09-2015 |
Output:
EMPNO |
ENAME |
SAL |
HIREDATE |
1001 |
KING |
20000 |
09/10 |
Elements of Date format method:
METHOD |
DESCRIPTION |
DD |
Numeric day of the month |
DY |
Three letter name of the day |
DAY |
Full name of the day |
MM |
Two digit value of the month |
MON |
Three letter name of the Month |
MONTH |
Full name of the month |
YYYY |
Full year in number |
YEAR |
Year name is spelledout |
Some other examples:
Output:
EMPNO |
ENAME |
SAL |
HIREDATE |
1001 |
KING |
20000 |
09
September 2010 |
TO_CHAR finction with numbers:
TO_CHAR number
conversion converts the number into character format.
Syntax:
Example:
Output:
Salary |
$5000 |
TO_DATE() conversion:
Ø This
function used to return the character value to a date format.
Ø Character
value is the input and date format is the returned value.
Example:1
Example:2
Example:3
Here,
HH24:MI:SS' This statement specifies the
hours , minutes, seconds.
OR
Select TO_DATE('2012/07/18 13:27:18', 'YYYY-MM-DD HH24:MI:SS')
from dual;
To_date in where condition:
Output:
ENAME |
HIREDATE |
KING |
20-DEC-2000 |
It converts a string
into a number.
To_number function
returns numeric value.
Syntax:
Example:
Output:
To_number(‘130.23’,’9G999D99’) |
130.23 |
No comments:
Post a Comment