oracle create program if not exists 1

oracle create program if not exists

DECLARE
    existing_program NUMBER;
BEGIN
    SELECT count(*) INTO existing_program
    FROM ALL_SCHEDULER_PROGRAMS WHERE PROGRAM_NAME = 'prog_name' AND OWNER='owner';
    IF existing_program = 1 THEN
        dbms_scheduler.DROP_PROGRAM(PROGRAM_NAME => 'prog_name');
    END IF;
END;
/
BEGIN DBMS_SCHEDULER.create_program(program_name => 'owner.prog_name', ...); END;

Here is what the above code is Doing:
1. It’s checking to see if the program already exists.
2. If it does, it’s dropping it.
3. It’s creating the program.

Similar Posts