I have a named UPDATE Query to do an SQL INSERT.
It works great when all parameters have values but, I get errors when passing NULL values to columns that allow Nulls.
Columns in the table include:
…
DATA_TYPE, CHAR, NULLABLE=No
NUMERIC_VALUE, NUMBER, NULLABLE=Yes
DATE_VALUE, DATE, NULLABLE=Yes
…
Depending on the value of DATA_TYPE (either ‘D’ or ‘N’), one of those parameters will be NULL.
Even though the database allows the columns to have NULLs, the NamedQuery throws exceptions when either parameter is passed a NULL value:
java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected DATE got NUMBER
For NULL Number or NULL Date respectively.
I was able to work around the invalid number by changing the parameter Data Type to string and changing the SQL query to recast the string as a number with:
to_number(:numberValue)
I’m still working on the string TO_DATE conversions to handle a NULL date.
Are there better ways of handling NULL parameters with Named Queries?
Is that a possible future enhancement?