Cursor,WHILE循环如何在DB2 i-Series中运行

时间:2015-02-03 12:40:43

标签: sql db2 iseries-navigator

只是想了解多少次" EXECUTE SQLStmt"运行时考虑DISTINCT Col返回5行,而COUNT(*)返回10行。

DECLARE c1 Cursor with return for 
SELECT Distinct Col as LIB FROM Page.Libraries 
ORDER BY Col;

SET numrecs = 0;
SET numcount = 1;
SET c_LIB = ' ';

SELECT COUNT(*) INTO numrecs FROM Page.Libraries;

OPEN c1;
WHILE numcount <= numrecs DO
    P2 : BEGIN
        FETCH c1 INTO c_LIB;
        SQLStmt = 'insert statement' || c_LIB
        EXECUTE IMMEDIATE SQLStmt;
        SET numcount = numcount + 1;
    END P2;
END WHILE;

我熟悉SQL Server,但对Db2语法感到困惑。

0 个答案:

没有答案