3

ソフトウェアに問題があり、問題を修正するために、アップグレード インストールのアップグレード プロセスの一部として実行されるストアド プロシージャを作成する必要があります。このストアド プロシージャは、特定の条件に一致する特定のテーブル内のすべての行を検索し、その行を更新する必要があります。内部的な理由により、データの挿入と更新専用に作成したストアド プロシージャを使用して更新を行う必要があります。

この問題を解決するために私が書いたストアド プロシージャは次のとおりです。

CREATE OR REPLACE FUNCTION FixDataProblem() RETURNS VOID AS $$
DECLARE
    FixCursor   NO SCROLL CURSOR FOR
        SELECT * FROM MyTable WHERE ProblemColumn IN ( '?', 'PR' );
    RowToUpdate         MyTable%ROWTYPE;
BEGIN
    -- Open the cursor
    OPEN FixCursor;

    -- Start a loop
    LOOP
        -- Fetch the next row from thr cursor
        FETCH FixCursor INTO RowToUpdate;

        -- Did we get anything back?
        IF RowToUpdate IS NULL THEN
            -- We didn't. Exit the loop
            EXIT;
        END IF;

        -- Call the UpsertMyTable stored procedure to set the ProblemColumn column to NULL
        SELECT CarSystem.UpsertMyTable( RowToUpdate.RowId,
                               RowToUpdate.ForeignId,
                               RowToUpdate.CountryId,
                               NULL,
                               RowToUpdate.Plate,
                               RowToUpdate.HashedData,
                               RowToUpdate.PlateClassId,
                               RowToUpdate.AlarmClassId,
                               RowToUpdate.BeginDate,
                               RowToUpdate.EndDate,
                               RowToUpdate.ListPriorityId,
                               RowToUpdate.VehicleTypeId,
                               RowToUpdate.MakeId,
                               RowToUpdate.ModelId,
                               RowToUpdate.Year,
                               RowToUpdate.ColorId,
                               RowToUpdate.Notes,
                               RowToUpdate.OfficerNotes,
                               NULL,
                               UUID_GENERATE_V4() );
    END LOOP;

    -- Close the cursor
    CLOSE ListDetailsCursor;
END;
$$ LANGUAGE plpgsql;

このストアド プロシージャは問題ありませんが、実行すると次のようになります。

ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function "fixdataproblem" line 22 at SQL statement


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

ERROR: query has no destination for result data
SQL state: 42601
Hint: If you want to discard the results of a SELECT, use PERFORM instead.
Context: PL/pgSQL function "fixdataproblem" line 22 at SQL statement

この問題を解決するにはどうすればよいですか? ストアド プロシージャを正しく呼び出していると思います。このストアドプロシージャの問題が何であるかは本当にわかりません。

ありがとう

トニー

4

1 に答える 1

6

そこには次のように書かれています。

ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function "fixdataproblem" line 22 at SQL statement

そして22行目:

    -- Call the UpsertMyTable stored procedure to set the ProblemColumn column to NULL
    SELECT CarSystem.UpsertMyTable( RowToUpdate.RowId,
    ...

SELECTからに変更しPERFORMます。PERFORM理由を参照してください。

于 2012-09-20T17:33:43.030 に答える