6-2. Converting a String to a Date

Problem

You need to convert some strings into DATE types. Let's say you have a requirement to insert date types into a database table column from one of your applications. The user is allowed to enter a date using your application's web page, but it is in a string format after the user submits the page. You need to convert this date from a string to a date type.

Solution

Use the TO_DATE function to convert the string values into the DATE type. This will allow your application to accept the date string in any format and convert it to a DATE type for you. The next example shows how to use the TO_DATE function:

my_val      DATE := TO_DATE('06/12/2010','MM/DD/YYYY');

You can convert the string through assignment, ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.