Db2使用了upper函数导致报错:SQL0433N Value "xxx" is too long. SQLSTATE=22001

环境:

DB2 10.5

 

问题现象及重现步骤:

Db2 的SQL语句报错:SQL0433N  Value "xxxxxxxxx" is too long.  SQLSTATE=22001,经过排查,发现是upper函数导致的,如果upper函数中的表达式超过32672个字符,就会出现这个问题,以下是重现步骤:

$ db2 "create table t1(stmt clob(2M))"
$ for i in `seq 1 32673`; do echo -e "A\c" >> t1.del; done
$ db2 "import from t1.del of del insert into t1"
$ db2 "select count(*) from t1 where upper(stmt) like 'abc%'"

1          
-----------
SQL0433N  Value "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" 
is too long.  SQLSTATE=22001

db2inst1@node01:~$ db2 "create table t1(stmt clob(2M))"
DB20000I  The SQL command completed successfully.
db2inst1@node01:~> rm t1.del
db2inst1@node01:~> for i in `seq 1 32673`; do echo -e "A\c" >> t1.del; done
db2inst1@node01:~> db2 "import from t1.del of del insert into t1"
SQL3109N  The utility is beginning to load data from file "t1.del".

SQL3115W  The field value beginning "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" in row 
"1" and column "1" is longer than the longest allowable table column.  The 
value was truncated.

SQL3125W  The character data in row "1" and column "1" was truncated because 
the data is longer than the target database column.

SQL3110N  The utility has completed processing.  "1" rows were read from the 
input file.

SQL3221W  ...Begin COMMIT WORK. Input Record Count = "1".

SQL3222W  ...COMMIT of any database changes was successful.

SQL3149N  "1" rows were processed from the input file.  "1" rows were 
successfully inserted into the table.  "0" rows were rejected.


Number of rows read         = 1
Number of rows skipped      = 0
Number of rows inserted     = 1
Number of rows updated      = 0
Number of rows rejected     = 0
Number of rows committed    = 1

db2inst1@node01:~> db2 "select count(*) from t1 where upper(stmt) like 'abc%'"

1          
-----------
SQL0433N  Value "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" 
is too long.  SQLSTATE=22001

db2inst1@node01:~> db2 "select length(stmt) from t1"

1          
-----------
      32673

  1 record(s) selected.
  

 

如果有人问你是怎么知道数字是32673的?答:二分法查找的,先从2000000开始,往下减。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值