HSQLDB 2.3.3:如何返回序列的下一个值的数组

时间:2015-12-03 19:11:25

标签: hsqldb

我有一个存储过程来返回序列的下一个值,但我需要序列的下一个“N”值。我想传入N作为NUMBEROFIDS参数,见下文。然后OUT GENERATEDID将成为ARRAY。这在HSQLDB中是否可行?

CREATE PROCEDURE MY_PROCEDURE(
    IN NUMBEROFIDS NUMERIC,
    OUT GENERATEDID NUMERIC)

    MODIFIES SQL DATA   

    BEGIN ATOMIC

    SELECT NEXT VALUE FOR MY_SEQUENCE INTO GENERATEDID FROM MY_TABLE;

    END;

1 个答案:

答案 0 :(得分:0)

您需要将参数声明为ARRAY并使用循环来填充数组。

CREATE PROCEDURE MY_PROCEDURE(
 IN NUMBEROFIDS INTEGER,
 OUT GENERATEDID NUMERIC ARRAY)
 BEGIN ATOMIC
  DECLARE GENID NUMERIC ARRAY;
  DECLARE COUNTER INTEGER DEFAULT 1;
  WHILE COUNTER <= NUMBEROFIDS DO
   SET GENID[COUNTER] = NEXT VALUE FOR MY_SEQUENCE;
  END WHILE;
  SET GENERATEDID = GENID;
 END;