6-4. Converting a Date to a String


You want to convert a date into a nicely formatted string value. For example, you are converting a legacy application from another database vendor into a web-based Oracle application. A few of the fields on the web form are dates. The users of the application expect to see the dates in a specific format, so you need the dates to be formatted in a particular manner for display.


Use the TO_CHAR function using the date masks. The TO_CHAR function offers many formatting options for returning a string from a DATE value. The following function accepts an EMPLOYEE_ID value and returns a representation of the HIRE_DATE spelled out.

CREATE OR REPLACE PROCEDURE obtain_emp_hire_date(emp_id IN NUMBER)

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.