Hi,
I am new to PL/SQL and trying to solve the following problem. I have a trigger on a table that is fired on INSERT/UPDATE on STARTINGTBL (i.e. TABLE), I am checking one of the inserted value against TABLE_CHECK2 (i.e. TABLE) and if I find a value, I am trying to
to grab all values matching the same value from CHECK_DATA_VIEW (i.e VIEW) and then inserting the values grabbed from a CHECK_DATA_VIEW in my FINAL_TBL (i.e. TABLE). I have a following cursor at the top and don't know why it's not working and complains on CD.CHECK1%TYPE i.e.
Following is my TRIGGER code.
Can someone please point me what am I doing wrong. I also want to have EXCEPTION HANDLING code too for each DML statement. Thanks
I am new to PL/SQL and trying to solve the following problem. I have a trigger on a table that is fired on INSERT/UPDATE on STARTINGTBL (i.e. TABLE), I am checking one of the inserted value against TABLE_CHECK2 (i.e. TABLE) and if I find a value, I am trying to
to grab all values matching the same value from CHECK_DATA_VIEW (i.e VIEW) and then inserting the values grabbed from a CHECK_DATA_VIEW in my FINAL_TBL (i.e. TABLE). I have a following cursor at the top and don't know why it's not working and complains on CD.CHECK1%TYPE i.e.
Code:
CURSOR C(CHECKINGDATA CD.CHECK1%TYPE) IS
SELECT CD.CHECK1,
CD.CHECK_2,
CD.CHECK_3
FROM CHECK_DATA_VIEW CD
WHERE CD.SOURCE = CHECKINGDATA;
Following is my TRIGGER code.
Code:
CREATE OR REPLACE TRIGGER TRGTST
AFTER INSERT OR UPDATE ON STARTINGTBL
DECLARE
VAR_CHECK1 CHECK_DATA_VIEW.CHECK1%TYPE;
VAR_CHECK_2 CHECK_DATA_VIEW.CHECK_2%TYPE;
VAR_CHECK_3 CHECK_DATA_VIEW.CHECK_3%TYPE;
VAR_COUNT NUMBER;
VAR_TEMP VARCHAR2(20);
CURSOR C(CHECKINGDATA CD.CHECK1%TYPE) IS
SELECT CD.CHECK1,
CD.CHECK_2,
CD.CHECK_3
FROM CHECK_DATA_VIEW CD
WHERE CD.SOURCE = CHECKINGDATA;
BEGIN
VAR_COUNT := 0;
IF :NEW.INSERTEDDB1 IS NOT NULL THEN
VAR_TEMP := TRIM(UPPER(:NEW.INSERTEDDB1));
SELECT COUNT(*) INTO VAR_COUNT
FROM TABLE_CHECK2
WHERE UPPER(INSERTEDDB2) = VAR_TEMP;
END IF;
IF VAR_COUNT > 0 THEN
OPEN C(:NEW.INSERTEDDB1);
LOOP
FETCH C INTO VAR_CHECK1, VAR_CHECK_2, VAR_CHECK_3;
EXIT WHEN C%NOTFOUND;
INSERT INTO FINAL_TBL(UNIQUE_ID,VALUE1,VALUE2,VALUE3) VALUES(TST_SEQ.NEXTVAL,VAR_CHECK_3,VAR_CHECK1,VAR_CHECK_2);
END LOOP;
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
Can someone please point me what am I doing wrong. I also want to have EXCEPTION HANDLING code too for each DML statement. Thanks