I am a little bit confused because of my SQL. I am trying to use the "Select Case Statement" to validate if a specific association exists, when existing it shouldn't do the insert statement. However, I can't use an insert statement in the "Then" clause. What am I doing wrong?
declare
cursor persons is
(Select Person_id
From PERSON_Table2Association_table p2c
Where P2C.ID in
(Select id
From Association_table
Where codepath like '&Old_Code_Path'
and tree_id = 10
);
new_codepath VARCHAR2(128) := '&New_Code_Path';
Begin
For person in persons
LOOP
select case
when not exists(Select Person_id
From PERSON_Table2Association_table p2c
Where P2C.ID in
(Select ctn.id
From Association_table ctn
Where codepath like '&New_Code_Path2'
and tree_id = 10)
and person_id = person.person_id
)
then (insert into PERSON_Table2Association_table -- here appears the error
Values ((Select ENTITYID.getnextval from dual),
0,
(Select id From Association_table Where codepath = new_codepath and tree_id = 10),
person.person_id,
9999,
null,
'ACCESS')
);
else DBMS_OUTPUT.put_line('Person has already this association')
END LOOP;
COMMIT;
END;
I hope you can help me. Thank you.