An Oracle operator can function across so many differing variables, statements, tables and datasets that keeping formatting straight can be one of the most difficult processes of all. Thankfully, Oracle is fairly clear in what it requires with formatting its data. Even when errors arise, the accompanying message tends to do a great job of specifying what exactly is at fault and gives the user a strong idea of where the error was emanating from and information on how to solve the formatting mistake.
The ORA-01830 complies with this concept, but the terminology it uses can seem a bit peculiar upon first viewing. So what do some of these terms mean, and how can a user utilize this information to make an educated correction to the error?
The ORA-01830 error states the following message: “date format picture ends before converting entire input string”. These terms do not seemingly fall in line with phrases that are more typically associated with Oracle software. Let us break this phrase down to get a better idea of what it means.
The “date format picture” referenced in the error message is the format mask. If you are conducting an explicit conversion using the TO_DATE function, the format picture is the second argument in the function. For instance, if the argument states the following:
to_date (‘2015-01-01 11:59:99’, ‘YYYY-MM-DD’ )
The format picture in this example is the “YYYY-MM-DD” portion of the function. So what exactly is the issue with this function? The “coordinates” within the parentheses do not match. In other words, the information in the X side (‘2015-01-01 11:59:99’) cannot be formatted into the lead example on the Y side (these are not graphing coordinates but may be easier to think about in this manner). Specifically, the time reference (’11:59:99’) is not stated in the YYYY-MM-DD section and therefore has no format for Oracle to reference.
The cause of an ORA-01830 error message is stated in Oracle docs “a valid date format picture included extra data. The first part of the format picture was converted into a valid date, but the remaining data was not required.” Knowing what we know now, we can assume that the extra data in the above case was the time data set. The first part of the format picture that was successfully converted was the date format, which matches the Y set. In this particular case, the time information was not required.
At this point, the ORA-01830 may be a bit clearer: the formatting of an input string was off. What does a user do from here?
The default date format in Oracle is typically DD-MON-YYYY. In order to correct the Oracle error, the user needs to edit the TO_DATE function to accommodate the extra information. Let us look at an example. Suppose that a user attempted to execute the following SQL statement:
INSERT INTO employer
(1, ‘WALMART’, ’07-MAY-2015 7:23 PM’);
The user would then receive the following error message:
ORA-01830: date format picture ends before converting entire input string
Based off of what we went over in the last section, we now know that we need to accommodate the information “7:23 PM”. To do this, edit in the following method:
INSERT INTO employer
(1, ‘WALMART’, TO_DATE(07-MAY-2015 7:23 PM’, ‘DD-MON-YYYY HH:MI PM’));
This should correct the error and allow the user to continue onward. As a note, other formatting issues, such as the X set listing seconds not listed in the Y or the month listed as “MON” the X and “MM” in the Y, can be corrected in the same manner.
As can be seen from the example juxtaposed against the message, the solution is much more user-friendly than the initial error message may let on. If you find other instances of errors causing a similar degree of frustration, or perhaps just need further clarification on formatting issues, a good next step would be to contact a trusted Oracle consultant for more information.