1

I have this query, using Hibernate 4 and DB2, running a native query:

select * from TABLE1 t where (:param1 is null or t.NAME = :param1)

That throws exception that null is invalid in the context (since SQL becomes select * from TABLE1 t where (null is null or t.NAME = null))

So I tried:

select * from TABLE1 t where (COALESCE(:param1,'!') = '!' or t.NAME = :param1)

That throws exception when I pass value "JUSTIN" -

"THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER  IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE"

Which appears to be cause by the fact that DB2 checks the length of ":param1" against "!".

Is there a way in DB2 to pass dynamic parameters?

I'm starting to hate DB2....

1 Answer 1

1

Turns out this works with Hibernate:

select * from TABLE1 t where NVL(:param1, t.NAME) = t.NAME;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.