Oracle - Field Starts With

The following script/procedure tests if a given Organization is the father of a second:

declare
dummy varchar2(500);
f_unit varchar2(50);
f_parent_unit varchar2(50);
begin
f_unit := 'AA-ABC';
f_parent_unit := 'AA-AB';
begin
select * into dummy
from dual
where f_unit like f_parent_unit || '%'
and f_unit != f_parent_unit;
dbms_output.put_line('DATA FOUND');
exception
when others then
dbms_output.put_line('NO DATA FOUND');
end;
end;
/


In a more general form you will only need:

begin
select * into dummy
from dual
where f_unit like f_parent_unit || '%'
and f_unit != f_parent_unit;
dbms_output.put_line('DATA FOUND');
exception
when others then
dbms_output.put_line('NO DATA FOUND');

Comments

Popular posts from this blog

Hibernate - HibernateException: createQuery is not valid without active transaction