You are on page 1of 3

create or replace function func_splitstreamingzone_tsid (streamingzone 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_splitstreamingzone_tsid('tucson.40447','streamingzone') from dual; --*/
--
/*--------------------------------------------------------------------------------
--------------------------*/

-- 1. streamingzone and type are the input variable


-- 2. streamingzone will get the streamingzone id
-- 3. type to extract whether streamingzone id ,or tsid

v_streamingzone 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 ('streamingzone','tsid') then

raise others;
end if;

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

if type = 'streamingzone' then

begin

v_streamingzone := substr(streamingzone,1,instr(streamingzone,'.',1,1)-1);

return v_streamingzone;

end;

end if;

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

if type = 'tsid' then

begin

v_streamingzone := substr(streamingzone,instr(streamingzone,'.',1,1)+1);

return v_streamingzone;

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 request a valid type - '||sqlcode||'
-error- '||sqlerrm);

end;

You might also like