to_char
TRANSCRIPT
-
8/3/2019 to_char
1/9
Oracle/PLSQL: To_Char Function
-
8/3/2019 to_char
2/9
In Oracle/PLSQL, the to_char function converts a number or date to a string.
The syntax for the to_char function is:
to_char( value, [ format_mask ], [ nls_language ] )
value can either be a number or date that will be converted to a string.
Examples - Numbers
The following are number examples for the to_char function.
to_char(1210.73, '9999.9') would return '1210.7'
to_char(1210.73, '9,999.99') would return '1,210.73'
to_char(1210.73, '$9,999.00') would return '$1,210.73'
to_char(21, '000099') would return '000021'
-
8/3/2019 to_char
3/9
Examples Dates
The following are date examples for the to_char function.
to_char(sysdate, 'yyyy/mm/dd'); would return '2003/07/09'
to_char(sysdate, 'Month DD, YYYY'); would return 'July 09, 2003'
to_char(sysdate, 'FMMonth DD, YYYY'); would return 'July 9, 2003' to_char(sysdate, 'MON DDth, YYYY'); would return 'JUL 09TH, 2003'
to_char(sysdate, 'FMMON DDth, YYYY'); would return 'JUL 9TH, 2003'
to_char(sysdate, 'FMMon ddth, YYYY'); would return 'Jul 9th, 2003'
You will notice that in some examples, the format_mask parameter beginswith "FM". This means that zeros and blanks are suppressed. This can beseen in the examples below.
'
-
8/3/2019 to_char
4/9
to_char(sysdate, 'FMMonth DD, YYYY'); would return 'July 9, 2003'
to_char(sysdate, 'FMMON DDth, YYYY'); would return 'JUL 9TH, 2003'
to_char(sysdate, 'FMMon ddth, YYYY'); would return 'Jul 9th, 2003
In Oracle/PLSQL, the to_date function converts a string to a date.
The syntax for the to_date function is:
to_date( string1, [ format_mask ], [ nls_language ] )
to_date('2003/07/09', 'yyyy/mm/dd') would return a date value ofJuly 9,2003.
to_date('070903', 'MMDDYY') would return a date value ofJuly 9, 2003.
to_date('20020315', 'yyyymmdd') would return a date value ofMar 15,
2002.
-
8/3/2019 to_char
5/9
In Oracle/PLSQL, the to_number function converts a string to a number.
The syntax for the to_number function is:
to_number( string1, [ format_mask ], [ nls_language] )
For example:
to_number('1210.73', '9999.99') would return the number 1210.73
to_number('546', '999') would return the number 546
to_number('23', '99') would return the number 23
to_number('1210.73'') would return the number 1210.73
-
8/3/2019 to_char
6/9
Oracle/PLSQL: CURSOR FOR Loop
The syntax for the CURSOR FOR Loop is:
FOR record_index in cursor_name
LOOP
{.statements.}
END LOOP;
You would use a CURSOR FOR Loop when you want to fetch and process every record in a
cursor. The CURSOR FOR Loop will terminate when all ofthe records in the cursor have been
fetched.
-
8/3/2019 to_char
7/9
CREATE OR REPLACE Function TotalIncome
( name_in IN varchar2 )RETURN number
IS
total_val number(6);
cursor c1 is
select monthly_income
from employeeswhere name = name_in;
BEGIN
total_val := 0;
FOR employee_rec in c1
LOOP
total_val := total_val + employee_rec.monthly_income;END LOOP;
RETURN total_val;
END;
-
8/3/2019 to_char
8/9
-
8/3/2019 to_char
9/9