background image
<< Getting the System Dates and Time | Converting a Character to a Number >>
<< Getting the System Dates and Time | Converting a Character to a Number >>

The results of the query appear

Retrieving Data with Queries
Querying and Manipulating Data 2-21
Example 2­31 Using TO_CHAR to Convert a Date Using a Format Template
SELECT first_name || ' ' || last_name "Name",
TO_CHAR(hire_date, 'FMMonth DD YYYY') "Date Started"
FROM employees;
The results of the query appear.
Name Date Started
---------------------------------------------- -----------------
Steven King June 17 1987
Neena Kochhar September 21 1989
Lex De Haan January 13 1993
...
107 rows selected
Your result set lists all the
hire_date
values in the new format.
Example 2­32
shows how you can use two standard format tags, Short Date (
DS
) and
Long Date (
DL
), to format your date.
Example 2­32 Using TO_CHAR to Convert a Date Using a Standard Format
SELECT first_name || ' ' || last_name "Name",
TO_CHAR(hire_date, 'DS') "Short Date",
TO_CHAR(hire_date, 'DL') "Long Date"
FROM employees;
The results of the query appear.
Name Short Date Long Date
--------------------------- ---------- -------------------------
Steven King 6/17/1987 Wednesday, June 17, 1987
Neera Kochhar 9/21/19889 Thursday, September 21, 1989
Lex De Haen 1/13/1993 Wednesday, January 13, 1993
...
107 rows selected
You can use the
TO_CHAR
function to convert a number to a desired currency format.
Example 2­33
will convert the
salary
values to a '
$99,999.99
' format. See Oracle
Database SQL Language Reference for
TO_CHAR
.
Example 2­33 Using TO_CHAR to Convert a Number to a Currency Template
SELECT first_name || ' ' || last_name "Name",
TO_CHAR(salary, '$99,999.99') "Salary"
FROM employees;
The results of the query appear.
Name Salary
---------------------------------------------- -----------
Steven King $24,000.00
Neena Kochhar $17,000.00
Lex De Haan $17,000.00
...
107 rows selected
Example 2­34
shows how you can use the
TO_NUMBER
function to convert a character
into a number that you can subsequently use in calculations. See Oracle Database SQL
Language Reference
for
TO_NUMBER
.