Using the DBVis SQL commander (as I am using "begin" and "end" in this code, I believe this code is executing in a PL SQL manner) I am trying to execute an sql script I have written to be my new "cleaning trigger"
I am trying to use IF EXISTS statements in this script to achieve cleaning ONLY when a certain column does actually contain data (APPROVED or REJECT)
This script aims to NOT use the insert (to other tables) statements (these will set off other triggers on other tables in an undesired way if they are used, even if there is no data for them to insert) unless there actually is (not null) data in a certain column:
begin
IF EXISTS (SELECT *
FROM HUB_SEGMENTS
where APP_OR_REJECT = 'APPROVED' or APP_OR_REJECT = 'REJECTED')
THEN
INSERT INTO
HUB_APPROVED (HUB_SEGMENTS_GUID, TID, SEGMENT, ID, ROLE, UPDATED_BY, APP_OR_REJECT, UPDATED_DATE)
SELECT
HUB_SEGMENTS_GUID, TID, SEGMENT, ID, ROLE, UPDATED_BY, APP_OR_REJECT, UPDATED_DATE
FROM
HUB_SEGMENTS WHERE APP_OR_REJECT = 'APPROVED';
INSERT INTO
HUB_REJECTED (HUB_SEGMENTS_GUID, TID, SEGMENT, ID, ROLE, UPDATED_BY, APP_OR_REJECT, UPDATED_DATE)
SELECT
HUB_SEGMENTS_GUID, TID, SEGMENT, ID, ROLE, UPDATED_BY, APP_OR_REJECT, UPDATED_DATE
FROM
HUB_SEGMENTS WHERE APP_OR_REJECT = 'REJECTED';
DELETE
FROM
"TESTDEMO".HUB_SEGMENTS
WHERE
APP_OR_REJECT = 'APPROVED' or APP_OR_REJECT = 'REJECTED';
DBMS_OUTPUT.PUT_LINE('Trigger: Insert to action Tables Executed');
ELSE
DBMS_OUTPUT.PUT_LINE('Trigger: Insert to action Tables Not Executed');
end;
I unfortunately get the following error message when I try and run this:
[Code: 6550, SQL State: 65000] ORA-06550: line 33, column 4:PLS-00103: Encountered the symbol ";" when expecting one of the following: if
I am pretty sure that this is down to the way that I have structured the IF EXIST
Of course, it may be that using IF EXIST in DBVis SQL commander,in my PL SQL code, isn't permissible - I haven't seen much documentation for this specific statement from oracle. If so, would there be a another way I might try and accomplish what I am trying to do here?
Any guidance would be greatly appreciated