Results 1 to 2 of 2
  1. #1
    Join Date
    May 2017

    Unanswered: Select with bind variable


    I was wondering the following, I have a java application connected to an oracle db that I am reworking for DB2.

    I have a lot of queries doing (extremely) simplified the following:

    select * from dual where :x = '123'
    If I enter a text with a length up to 3 long the query runs successfully, however if I enter a text of 4 characters it fails with a message:

    The value of a host variable in the EXECUTE or OPEN statement is out of range for its corresponding use.. SQLCODE=-302, SQLSTATE=22001, DRIVER=4.18.60
    If I do it with a cast then it works:

    select * from dual where :x = CAST('123' AS VARCHAR(6));
    In oracle no cast is needed and no error is thrown if the lengt of the variable is > 3.

    Problem is that I do not know the length in advance and I would not like to adapt every query with a cast. Is there an option on jdbc level, schema level, ... that allows me to avoid the casting?

    Thank you,

  2. #2
    Join Date
    Jun 2017
    Provided Answers: 1
    I don't have an answer specifically to your question but do you know db2 has an oracle compatibility mode? Perhaps that may make things work like you want?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts