Я заменил курсоры на , выделил и изменил вашу процедуру на АВТОНОМНО , и она будет работать, но я рекомендую вам не обновлять ту же таблицу в триггер и, возможно, вставить в другую таблицу, например: FINALIZED_TRANSACTIONS.
Вот мой код для вашего триггера:
CREATE OR REPLACE TRIGGER INSERT_FINAL_WORKPLACE
BEFORE UPDATE
ON TRANSACTIONS
FOR EACH ROW
BEGIN
SELECT COUNT (ORDER_ID), COUNT (DECODE (STATE, 'accept', ORDER_ID, NULL))
INTO VAR_O_ALL, VAR_O_ACT
FROM TRANSACTIONS
WHERE ORDER_ID = PI_TRA_ORDER_ID;
IF VAR_O_ALL = VAR_O_ACT AND :NEW.ORDER_ID IS NULL
THEN
CON_API_PKG.CREATEFINISHTRANSACTION (
:NEW.ORDER_ID,
:NEW.PRODUCT_ID,
:NEW.NOTE,
:NEW.REPORTER_ID
);
END IF;
END;
Вот мой код для вашей процедуры:
CREATE OR REPLACE PROCEDURE CREATEFINISHTRANSACTION (
PI_TRA_ORDER_ID IN TRANSACTIONS.ORDER_ID%TYPE,
PI_PRODUCT_ID IN TRANSACTIONS.PRODUCT_ID%TYPE,
PI_NOTE IN TRANSACTIONS.NOTE%TYPE,
PI_REPORTER_ID IN TRANSACTIONS.REPORTER_ID%TYPE)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
VAR_WORKPLACE_ID FINAL_WORKPLACE.WORKPLACE_ID%TYPE;
BEGIN
BEGIN
SELECT FW.WORKPLACE_ID
INTO VAR_WORKPLACE_ID
FROM FINAL_WORKPLACE FW
WHERE PI_PRODUCT_ID = FW.PRODUCT_ID;
EXCEPTION
WHEN OTHERS
THEN
--Handle exception by displaying dbms output or insert into a log table
ROLLBACK;
END;
INSERT
INTO TRANSACTIONS (
TRANSACTION_ID,
PRODUCT_ID,
CREATED,
NOTE,
WORKPLACE_ID,
REPORTER_ID,
ORDER_ID,
PHASE
)
VALUES (
(SELECT MAX (TRANSACTION_ID) FROM TRANSACTIONS) + 1,
PI_PRODUCT_ID,
CURRENT_TIMESTAMP,
PI_NOTE,
VAR_WORKPLACE_ID,
PI_REPORTER_ID,
PI_TRA_ORDER_ID,
'final');
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
--Handle exception by displaying dbms output or insert into a log table
ROLLBACK;
END;