开发者

while function in postgresql

I want to insert records to a table by function.

CREATE OR REPLAC开发者_开发问答E FUNCTION insert_wilda()
    RETURNS integer AS
$BODY$
DECLARE
    countKab integer;
    i integer;
BEGIN
    i := 1;
    SELECT count(*)+34 into countKab from m_kab
    WHILE (i <= countKab)
    loop

        INSERT INTO "t_historyWilda"("kdHistory","kdProp","kdKab","kdKec","nmWilda","noUrut",bulan,tahun,"isActive")
        SELECT 'i',"kdProp","kdKab",'000',"namaKab",'1', EXTRACT(MONTH FROM TIMESTAMP 'now()'), EXTRACT(YEAR FROM TIMESTAMP 'now()'),'1' FROM m_kab
    end loop;
    RETURN i;
END;
$BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;

But I got error like this:

ERROR:  syntax error at or near "<="
LINE 10:  WHILE (i <= countKab)
                   ^

********** Error **********

ERROR: syntax error at or near "<="


You missed ';' after this line

SELECT count(*)+34 into countKab from m_kab
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜