Clicky

Oracle - Field Starts With

February 15, 2013

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’);