DECLARE
    aux user_constraints.search_condition%TYPE;
    sys_condition user_constraints.search_condition%TYPE;
    manual_condition user_constraints.search_condition%TYPE;
    constname user_constraints.constraint_name%TYPE;
    cursor names IS
        SELECT constraint_name
            FROM user_constraints
            WHERE table_name LIKE 'DT462'
            AND constraint_type = 'C';
    cursor search IS
         SELECT search_condition
            FROM user_constraints
            WHERE table_name LIKE 'DT462'
            AND constraint_type = 'C';
    constraint_amount number;   
    constraint_count number;
BEGIN
    OPEN names;
    OPEN search;
    constraint_count := 0;
    
    select count(*) into constraint_amount
            FROM user_constraints
            WHERE table_name LIKE 'DT462'
            AND constraint_type = 'C';
            
    manual_condition := 'DI001092 is not null';
    sys_condition := '"DI001092" IS NOT NULL';

    LOOP
        FETCH names INTO constname;
        FETCH search INTO aux;

        IF aux in (sys_condition, manual_condition) THEN
            dbms_output.put_line('Selected constraint to drop: '|| constname);
            EXECUTE IMMEDIATE ('ALTER TABLE DT462 DROP CONSTRAINT ' || constname);
            dbms_output.put_line('Constraint dropped succesfully' || constname);
        END IF;
        
        constraint_count := constraint_count + 1;
        EXIT WHEN constraint_count = constraint_amount;
    END LOOP;

    CLOSE names;
    CLOSE search;
    
    EXECUTE IMMEDIATE ('ALTER TABLE DT462 DROP CONSTRAINT ' || constname);
    COMMIT;
    
END;