Breaking News
You are here: Home / Notes / SEM-3 / RDBMS / CONVERSION FUNCTIONS

CONVERSION FUNCTIONS

CONVERSION FUNCTIONS

datatype_conversion_functions

 

TO_NUMBER: Converts char, a CHARACTER value expressing a number, to a NUMBER datatype.

SYNTAX:

TO_NUMBER(char)

EXAMPLE:

UPDATE ACCT_MSTR SET Curbal = Curbal + TO_NUMBER(SUBSTR(‘$100’,2,3));

OUTPUT:

10 rows updated

 

TO_CHAR: (number conversion): Converts a value of a NUMBER datatype to a character datatype, using the optional format string. TO_CHAR() accepts a number (n) and a numeric format (fmt) in which the number has to appear. If fmt is omitted, n is converted to a char value exactly long enough to hold all significant digits.

SYNTAX:

TO_CHAR(n[,fmt])

EXAMPLE:

SELECT TO_CHAR(17145,’4099,999’) “Char” FROM DUAL;

OUTPUT:

Char

————–

$017,145

 

TO_CHAR: (date conversion): Converts a value of a DATE datatype to a CHAR value, TO_CHAR) accepts a date, as well as the format (fmt) in which the date has to appear. Fmt must be a date format. If fmt is omitted, the date is converteharacter value using the default date format, i.e. “DD-MON-YY”.

SYNTAX:

TO_CHAR(date[,fmt])

EXAMPLE:

SELECT TO_CHAR(DT,’Month DD, YYYY’) “New Date Format” FROM Trans_Mstr

where Trans_No = ‘T1’;

OUTPUT:

New Date Format

—————————

January   05,  2003

Download Paper Solutions from Below Link

About admin

Scroll To Top