私は初めてですPL/pgSQL
。テーブルにデータを挿入しようとすると、次の関数でエラーが発生します。このリンクはエラーを定義していますが、このリンクの問題を理解できません。
CREATE OR REPLACE FUNCTION updateScore()
RETURNS void AS
$$
DECLARE
singleTopicCriteriaPercentage DECIMAL(6,6);
sitePercentage DECIMAL(6,6);
singleSiteCriteriaPercentage DECIMAL(6,6);
totalSocre DECIMAL(6,6);
cursor1 CURSOR FOR select id from sitereviews order by id;
cursor2 CURSOR FOR select weight into rating from sitereviews_ratingcriteria where site_id = id;
id sitereviews.id%TYPE;
weights sitereviews_ratingcriteria.weight%TYPE;
BEGIN
singleTopicCriteriaPercentage := (10.0 / 120.0) * 100.0;
sitePercentage := 0.0;
singleSiteCriteriaPercentage := 0.0;
totalSocre := 0.0;
OPEN cursor1;
LOOP
FETCH cursor1 INTO id;
EXIT WHEN NOT FOUND;
totalSocre := 0.0;
OPEN cursor2;
LOOP
FETCH cursor2 INTO weights;
EXIT WHEN NOT FOUND;
sitePercentage := singleTopicCriteriaPercentage * weights;
singleSiteCriteriaPercentage := (sitePercentage / 100) * 10;
totalSocre := singleSiteCriteriaPercentage + totalSocre;
END LOOP;
CLOSE cursor2;
update sitereviews set weights := round(totalSocre) WHERE CURRENT OF cursor1;
END LOOP
CLOSE cursor1;
END;
$$ LANGUAGE 'PLPGSQL'
以下はコンパイル時エラーです。
ERROR: syntax error at or near "$1"
LINE 1: update sitereviews set $1 := round( $2 ) WHERE CURRENT OF ...
^
QUERY: update sitereviews set $1 := round( $2 ) WHERE CURRENT OF $3
CONTEXT: SQL statement in PL/PgSQL function "updatescore" near line 35
********** Error **********
ERROR: syntax error at or near "$1"
SQL state: 42601
Context: SQL statement in PL/PgSQL function "updatescore" near line 35