1. 程式人生 > >pgsql 通過 序列 批量獲取ID

pgsql 通過 序列 批量獲取ID

CREATE OR REPLACE FUNCTION getNextIds (VARCHAR,INTEGER) RETURNS VARCHAR AS $body$
DECLARE str VARCHAR ;
DECLARE nextid VARCHAR ;
BEGIN

    str = '';
    FOR i in 1..$2 loop
        nextid = (SELECT NEXTVAL($1));
        str = str || nextid || ';' ;
    END loop;

    RETURN str ;
END ; 
$body$ 
LANGUAGE 'plpgsql';