sql - Need assistance with IF Exists then Insert -
im trying run cant figure out why not. trying create pl/sql block read in 2 codes , make sure exist before inserting:
declare v_old_atty_id in atty_rules.attorney_id%type; v_new_atty_id in atty_rules.attorney_id%type; type rule_array varray(10000) of number; v_rule rule_array; begin select distinct rule_id bulk collect v_rule atty_rules attorney_id = v_old_atty_id , date_activated <= sysdate , sysdate < nvl(date_deactivated, sysdate+1); if exists (select attorney_id org_attys attorney_id = v_new_atty_id) indx in 1..v_rule.count loop insert atty_rules (attorney_id,rule_id) values (v_new_atty_id, v_rule(indx)); end loop else dbms_output.put_line('doesnt exist') end if; end; any direction lot, thank you.
try way:
select count(attorney_id) v_count org_attys attorney_id = v_new_atty_id if v_count > 0 indx in 1..v_rule.count loop insert atty_rules (attorney_id,rule_id) values (v_new_atty_id, v_rule(indx)); end loop else dbms_output.put_line('doesnt exist') end if;
Comments
Post a Comment