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 badges1 Answer
Reset to default 2I'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))),
...
)
本文标签:
版权声明:本文标题:sql - In DB2, does function trim() make varchar longer? It seems to be causing a sql302 error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741462275a2380108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论