运行plpgsql程序来更新表中的数据

时间:2013-05-15 07:19:53

标签: sql postgresql cursor plpgsql

我正在使用Postgres 8.4。我想使用plpgsql和游标更新数据。当我尝试运行plpgsql时会产生错误。

CREATE OR REPLACE FUNCTION updateScore() 
RETURNS void AS
$$
DECLARE
singleTopicCriteriaPercentage   DECIMAL(6,10);
sitePercentage          DECIMAL(6,10);
singleSiteCriteriaPercentage    DECIMAL(6,10);
totalSocre          DECIMAL(6,10);

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;
weight              sitereviews_ratingcriteria.weight%TYPE;

BEGIN
singleTopicCriteriaPercentage := (10 / 120) * 100;
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 weight;
    EXIT WHEN NOT FOUND;
        sitePercentage := singleTopicCriteriaPercentage * weight;
        singleSiteCriteriaPercentage :=  (sitePercentage / 100) * 10;
        totalSocre := singleSiteCriteriaPercentage + totalSocre;
    END LOOP;
    CLOSE cursor2;

    update sitereviews set weight = : round(totalSocre)  WHERE CURRENT OF cursor1;
END LOOP
CLOSE cursor1;
END;
$$ LANGUAGE 'PLPGSQL'

以下是尝试运行此程序时的错误:

ERROR: could not load library "C:/Program Files/PostgreSQL/8.4/lib/plpgsql.dll": The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
 SQL state: 58P01

1 个答案:

答案 0 :(得分:2)

看起来你的PostgreSQL安装不完整或者它已经坏了。在较旧的PostgreSQL安装程序中,plpgsql是可选的。所以,请检查您的安装。