Vous êtes sur la page 1sur 3

create or replace function func_splitservicehubheadend (servicegroup in

varchar2,type in varchar2)

return varchar2

is

--
/*--------------------------------------------------------------------------------
--------------------------*/
--/*--created by : venkatesan s
--------------------------------------------------------------------*/
--/*--datelastmodified : 02-mar-2008
---------------------------------------------------------------------*/
--/*--purpose : to extract the servicegroup_id ,hub and headend from
the servicegroup field ----*/
--/* given in the source file as in combined format
----------------------------------*/
--/* the delimiter used to split the data is '.' (dot)
-------------------------------*/
--/*--version : 1.0
-----------------------------------------------------------------------------*/
--/*--sample : select func_splitservicehubheadend
('abcd.def.ghi','headend') from dual;---------*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

-- 1. servicegroup and type are the input variable


-- 2. servicegroup will get the service groupid
-- 3. type to extract whether servicegroupid,hubid or headend

v_servicegroup varchar2(50); --to return the output


others exception; --for exception

begin

--
/*--------------------------------------------------------------------------------
--------------------------*/
--/*------to check whether user requested type which is listed in function
-----------------------------------*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

if type not in ('servicegroup','hub','headend') then

raise others;
end if;

--
/*--------------------------------------------------------------------------------
--------------------------*/
--/*------if the user requested servicegroup as type then it will returns
servicegroupid as output------------*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

if type = 'servicegroup' then

begin

v_servicegroup := substr(servicegroup,1,instr(servicegroup,'.',1,1)-1);

return v_servicegroup;

end;

end if;

--
/*--------------------------------------------------------------------------------
--------------------------*/
--/*------if the user requested hub as type then it will returns hubid as
output------------------------------*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

if type = 'hub' then

begin

v_servicegroup :=
substr(servicegroup,instr(servicegroup,'.',1,1)+1,(length(servicegroup)-
length(substr(servicegroup,instr(servicegroup,'.',1,2)+1))-
instr(servicegroup,'.',1,1))-1);
return v_servicegroup;

end;

end if;

--
/*--------------------------------------------------------------------------------
--------------------------*/
--/*------if the user requested headend as type then it will returns headend as
output------------------------*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

if type = 'headend' then

begin

v_servicegroup := substr(servicegroup,instr(servicegroup,'.',1,2)+1);
return v_servicegroup;

end;

end if;

--
/*--------------------------------------------------------------------------------
--------------------------*/
--/*------to raise the application error if the input variable type is not in the
listed types ---------------*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

exception

when others then


raise_application_error(-20001,'please change your type or enter the valid
servicegroup - '||sqlcode||' -error- '||sqlerrm);

end;

Vous aimerez peut-être aussi