O'Reilly logo

Oracle and PL/SQL Recipes: A Problem-Solution Approach by Matt Arena, Josh Juneau

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6-4. Converting a Date to a String

Problem

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.

Solution

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)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required