admin管理员组

文章数量:1289867

I'm using IBatis with DB2.

I have a table and content column is defined as VARCHAR(2000) in the table.

At first, I tried to insert data into the table with the following query

INSERT INTO TABLE
(...,
content,
...
)
VALUES
(...,
TRIM(#content:VARCHAR#),
...
)

It gave a SQL302 error, even thought the data was only 400 bytes.

The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use.

And then I found out that it worked well except for trim()

Why are these errors coming up? Did I do some thing wrong?

I'm using IBatis with DB2.

I have a table and content column is defined as VARCHAR(2000) in the table.

At first, I tried to insert data into the table with the following query

INSERT INTO TABLE
(...,
content,
...
)
VALUES
(...,
TRIM(#content:VARCHAR#),
...
)

It gave a SQL302 error, even thought the data was only 400 bytes.

The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use.

And then I found out that it worked well except for trim()

Why are these errors coming up? Did I do some thing wrong?

Share Improve this question edited Feb 20 at 2:40 Dale K 27.5k15 gold badges58 silver badges83 bronze badges asked Feb 20 at 1:55 DoodoongsilDoodoongsil 136 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

I'm not familiar with iBatis, but I'm assuming the #content:VARCHAR# syntax is just its way to provide a parameter value. What is probably happening is that without specifying the length, it will default to the maximum size of a VARCHAR type.

There may be a way to specify this in iBatis, but you could surround your variable with a CAST(... AS VARCHAR(2000)) to be explicit:

INSERT INTO TABLE
(...,
content,
...
)
VALUES
(...,
TRIM(CAST(#content:VARCHAR# AS VARCHAR(2000))),
...
)

本文标签: