4

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 "<="

1 Answer 1

7

You missed ';' after this line

SELECT count(*)+34 into countKab from m_kab
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.