Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle Error

Status
Not open for further replies.

getjbb

MIS
Jun 4, 2003
139
US
In Oracle 9i I am trying to assign variables declared as a string to a date field. I am getting the following error:
ORA-01858: a non-numeric character was found where a numeric was expected

The code is as follows:

v_mnth VARCHAR2 DEFAULT NULL,
v_day VARCHAR2 DEFAULT NULL,
v_yr VARCHAR2 DEFAULT NULL

v_date DATE := to_date(v_mnth|| '/' ||v_day || '/' || v_yr,'MM/DD/YYYY');

But, when I hardcode a value for v_mnth, v_day and v_yr I do not get the error.

I do not understand what is wrong.

I appreciate your help in advance.

getjbb


 
Try doing your concatenation in the executable part of your code - or initializing the values of your variables. By doing the concatenation in your declaration, with your variable set to NULL, you are asking Oracle to convert the string '//' into a date - and that will not fly!
 
Thanks, tarn and carp. I will give your suggestions a try.
 
getjbb -
The following will work:
Code:
DECLARE
   v_mnth VARCHAR2(5) := '02';
   v_day VARCHAR2(5) := '08';
   v_yr VARCHAR2(5) := '2012';
   v_date DATE;
BEGIN
v_date := to_date(v_mnth|| '/' ||v_day || '/' || v_yr,'MM/DD/YYYY');
END;
but only because I have initialized the first three variables to non-null values. Without these values, I get the same error that you are reporting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top