I want to insert records to a table by function.

CREATE OR REPLACE 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 "<="
share|improve this question
feedback

1 Answer

You missed ';' after this line

SELECT count(*)+34 into countKab from m_kab
share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.