seed111758
seed111758
2016-08-08 14:56

db2在函数中使用游标问题

在BD2函数中使用游标总是提示格式错误,请大神帮忙看一下是什么地方 的问题,代码如下
CREATE FUNCTION GET_IMPORT_SQL(IN_TBNAME VARCHAR(50))
RETURNS VARCHAR(3000)
LANGUAGE SQL
BEGIN ATOMIC
DECLARE v_COUNT INT DEFAULT 0;
DECLARE v_IMPORT_SQL VARCHAR(3000) DEFAULT '';
DECLARE v_NAME VARCHAR(50);
DECLARE v_COLTYPE VARCHAR(50);
DECLARE v_LENGTH DOUBLE;
DECLARE v_SCALE DOUBLE;
DECLARE v_CUR CURSOR FOR
SELECT NAME,COLTYPE,LENGTH,SCALE FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = IN_TBNAME ORDER BY COLNO FOR READ ONLY;
SET v_COUNT = (SELECT COUNT(*) FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = IN_TBNAME);
WHILE v_COUNT > 0 DO
FETCH FROM v_CUR INTO v_NAME,v_COLTYPE,v_LENGTH,v_SCALE;
SET v_IMPORT_SQL = v_IMPORT_SQL || v_NAME;
SET v_COUNT = v_COUNT-1;
END WHILE;
CLOSE v_CUR;
RETURN v_IMPORT_SQL;
END;

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换