Я портирую функцию Oracle в Postgres PGPLSQL .. Я использовал это руководство: http://www.postgresql.org/docs/8.1/static/plpgsql.html
CREATE OR REPLACE PROCEDURE DATA_UPDATE
(mission NUMBER,
task NUMBER)
AS
BEGIN
IF mission IS NOT NULL THEN
UPDATE MISSION_OBJECTIVE MO
SET (MO.MO_TKR_TOTAL_OFF_SCHEDULED,
MO.MO_TKR_TOTAL_RECEIVERS) =
(SELECT NVL(SUM(RR.TRQ_FUEL_OFFLOAD),0),
NVL(SUM(RR.TRQ_NUMBER_RECEIVERS),0)
FROM REFUELING_REQUEST RR, MISSION_REQUEST_PAIRING MRP
WHERE MO.MSN_INT_ID = MRP.MSN_INT_ID
AND MO.MO_INT_ID = MRP.MO_INT_ID
AND MRP.REQ_INT_ID = RR.REQ_INT_ID)
WHERE MO.MSN_INT_ID = mission
AND MO.MO_INT_ID = task ;
END IF ;
COMMIT ;
END ;
У меня так далеко:
CREATE OR REPLACE FUNCTION DATA_UPDATE
(NUMERIC,
NUMERIC)
RETURNS integer as '
DECLARE
mission ALIAS for $1;
task ALIAS for $2;
BEGIN
IF mission IS NOT NULL THEN
UPDATE MISSION_OBJECTIVE MO
SET (MO.MO_TKR_TOTAL_OFF_SCHEDULED,
MO.MO_TKR_TOTAL_RECEIVERS) =
(SELECT COALESCE(SUM(RR.TRQ_FUEL_OFFLOAD),0),
COALESCE(SUM(RR.TRQ_NUMBER_RECEIVERS),0)
FROM REFUELING_REQUEST RR, MISSION_REQUEST_PAIRING MRP
WHERE MO.MSN_INT_ID = MRP.MSN_INT_ID
AND MO.MO_INT_ID = MRP.MO_INT_ID
AND MRP.REQ_INT_ID = RR.REQ_INT_ID)
WHERE MO.MSN_INT_ID = mission
AND MO.MO_INT_ID = task ;
END IF;
COMMIT;
END;
' LANGUAGE plpgsql;
Это ошибка, которую я получаю:
ERROR: syntax error at or near "SELECT"
LINE 1: ...OTAL_OFF_SCHEDULED, MO.MO_TKR_TOTAL_RECEIVERS) = (SELECT COA...
Я не знаю, почему это не работает ... есть идеи?