SoftwareSavant
SoftwareSavant

Reputation: 9737

ORA-01830 Oracle Exception from .net Stored Proc Call

I am passing in Dates into an Oracle stored procedure. I keep managing to get the above exception. That Exception I am guessing is being caused by an incorrect dateTime format on my part. The stored proc requires military time for the dates and is in the Format of 28-Dec-12 11:29:59. The stored proc takes strings and converts them to the right time inside the stored proc... Here is how I set up the correct parameter...

cmd.Parameters.Add(colName[i], DateTime.Parse(trueDateStr).ToString("dd-MMM-yy HH:mm:ss"));

One stored proc parameter that is giving me indigestion is this one...

ACTIVE_DATEIn
to_date(ACTIVE_DATEin,'DD-MON-YY')

The second line is a line a little later on in the stored proc... The first line is the actual parameter that gets passed in. Sometimes that parameter might be null... What I do is I check if it is null, and then I pass in an empty string... Will that empty string cause an error? Should I pass it some kind of Null Date value or empty date value? What is your opinion on that?

Upvotes: 2

Views: 2691

Answers (2)

Codo
Codo

Reputation: 78815

The problem most likely is that you're passing a string containing date and time while Oracle only expects the date part. That's exactly what the error message says (after the date part has been successfully parsed there are still characters in the input string but not in the date format):

ORA-01830: date format picture ends before converting entire input string

So the fix could be:

cmd.Parameters.Add(colName[i], DateTime.Parse(trueDateStr).ToString("dd-MMM-yy"));

And passing in an empty string for NULLs is okay. Oracle treats empty strings as NULL and the TO_DATE function handles NULL values just fine.

Upvotes: 3

Matten
Matten

Reputation: 17621

The error may arise from you call to to_date with the wrong format_mask, see here. Use the following statement instead

to_date(ACTIVE_DATEin, 'DD-MON-YY HH24:MI:SS')

Upvotes: 0

Related Questions