A very good post on propertySource and Environment

http://blog.jamesdbloom.com/UsingPropertySourceAndEnvironment.html

Advertisements

reset sequence

create or replace
procedure reset_seq( p_seq_name in varchar2 )
is
    l_val number;
begin
    execute immediate
    'select ' || p_seq_name || '.nextval from dual' INTO l_val;

    execute immediate
    'alter sequence ' || p_seq_name || ' increment by -' || l_val || 
                                                          ' minvalue 0';

    execute immediate
    'select ' || p_seq_name || '.nextval from dual' INTO l_val;

    execute immediate
    'alter sequence ' || p_seq_name || ' increment by 1 minvalue 0';
end;

disable/enable constraints

CREATE OR REPLACE PROCEDURE sp_dat_disable_constraints
IS
BEGIN
FOR i IN (SELECT table_name, constraint_name FROM user_constraints WHERE owner=’DAT’ AND constraint_type=’R’ AND status=’ENABLED’) LOOP
EXECUTE IMMEDIATE ‘ALTER TABLE ‘ || i.TABLE_NAME || ‘ DISABLE CONSTRAINT ‘ || i.constraint_name;
END LOOP i;
END;

CREATE OR REPLACE PROCEDURE sp_dat_enable_constraints
IS
BEGIN
FOR i IN (SELECT table_name, constraint_name FROM user_constraints WHERE owner=’DAT’ AND status=’DISABLED’) LOOP
EXECUTE IMMEDIATE ‘ALTER TABLE ‘ || i.TABLE_NAME || ‘ ENABLE CONSTRAINT ‘ || i.constraint_name;
END LOOP i;
END;