IBM i的Db2中的EXECUTE具有不同的功能
因此,使用以下内容:
我有一个包含以下行的过程:
ITERATOR的值在循环中动态设置
DECLARE V_LOSS_ID integer;
DECLARE V_STATE_CODE CHARACTER(2);
DECLARE V_CLASS_CODE CHARACTER(4);
SET V_QUERY = 'set (?,?,?) = (select LOSS_ID, STATE_CODE, CLASS_CODE from LOSS L limit 1 offset '|| ITERATOR || ' )';
PREPARE STMT FROM V_QUERY;
EXECUTE STMT into V_LOSS_ID, V_STATE_CODE, V_CLASS_CODE;
我在iSeries db2中得到以下错误-[SQL0104]令牌V_LOS_ID无效。有效标记:SQL DESCRIPTOR。
但是,此过程适用于DB2LUW数据库。仅在DB2 iseries as400数据库上面临此问题
因此,使用以下内容:
DECLARE ITERATOR ...;
DECLARE V_LOSS_ID integer;
DECLARE V_STATE_CODE CHARACTER(2);
DECLARE V_CLASS_CODE CHARACTER(4);
DECLARE C1 CURSOR FOR STMT;
...
--SET V_QUERY = 'set (?,?,?) = (select LOSS_ID, STATE_CODE, CLASS_CODE from LOSS L limit 1 offset '|| ITERATOR || ' )';
SET V_QUERY = 'select LOSS_ID, STATE_CODE, CLASS_CODE from LOSS L limit 1 offset '|| ITERATOR;
PREPARE STMT FROM V_QUERY;
--EXECUTE STMT into V_LOSS_ID, V_STATE_CODE, V_CLASS_CODE;
OPEN C1;
FETCH C1 INTO V_LOSS_ID, V_STATE_CODE, V_CLASS_CODE;
CLOSE C1;