当前位置: 代码迷 >> DB2 >> 存储语句报错 一头雾水,该如何解决
  详细解决方案

存储语句报错 一头雾水,该如何解决

热度:6970   发布时间:2013-02-26 00:00:00.0
存储语句报错 一头雾水
错误提示 不可将值赋给SELECT VALUES FETCH或赋值语句的主变量,因为数据类型不兼容 40行 也就是定位到open colc(游标),求各位大神帮忙解答

-- Start of generated script for 132.228.167.4-EDWTST-EDWDEV (jsctetl)
-- Jul-20-2011 at 17:10:18

SET SCHEMA JSCTETL ;

SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","JSCTETL";

CREATE PROCEDURE BML.DEL_ENTER ( ) 
  LANGUAGE SQL
  NOT DETERMINISTIC
  CALLED ON NULL INPUT
  EXTERNAL ACTION
  OLD SAVEPOINT LEVEL
  MODIFIES SQL DATA
  INHERIT SPECIAL REGISTERS --15行
  begin
  --变量声明
Declare tabn varchar(150);
Declare coln varchar(150);
Declare exesql varchar(500);--20
declare sqlcode integer default 0;
Declare insertsql varchar(150);
Declare returnv INTEGER ;
--statement声明
Declare strs statement;
--游标声明
declare tabc cursor for
select cast(table_name as varchar(150)) from sysibm.tables where TABLE_SCHEMA = 'BML';
Declare colc cursor for strs;
--查找tabn表相应类型的字段30
set exesql='select cast(COLUMN_NAME as varchar(150)) from sysibm.columns where table_name='''||tabn ||'''and data_type in (''CHARACTER'',''CHARACTER LARGE OBJECT'',''CHARACTER VARYING'')';
prepare strs from exesql;
execute strs; 
open tabc;
loop1:
loop
FETCH tabc INTO tabn;
if sqlcode=100 then leave loop1;
else
Open colc;
loop2:
loop
FETCH colc INTO coln;
if sqlcode=100 then leave loop2;
else
set exesql='SELECT cast((count(*) as INTEGER) FROM BML.'||tabn ||'WHERE POSSTR('''||coln||''' ,CHR(10))>0 OR POSSTR('''|| coln|| ''',CHR(13))>0';
values exesql into returnv;
if returnv<>0 then
set insertsql='insert BML.tmp_result values('''||tabn||''','||coln||''')';
execute immediate insertsql;
end if;
FETCH colc INTO coln;
end if;
End loop;
FETCH tabc INTO tabn;
Close colc;
end if;
end loop;
Close tabc;
End;

#SYNC 10;



-- End of generated script for 132.228.167.4-EDWTST-EDWDEV (jsctetl)

------解决方案--------------------------------------------------------
把报错的详细信息贴出来,包括sqlcode,sqlstat
------解决方案--------------------------------------------------------
检查游标的数据类型与FETCH 是否一致
------解决方案--------------------------------------------------------
恭喜。。。