CREATE OR REPLACE FUNCTION F_CONCAT_ROW_COMMUNITY_LABEL(p_field IN VARCHAR2,
p_parent_id IN VARCHAR2,
p_splicing IN VARCHAR2)
RETURN VARCHAR2 IS
retResult VARCHAR2(32767);
TYPE cur_type IS REF CURSOR;
rscur cur_type;
rsVal VARCHAR2(2000);
cnt INTEGER;
BEGIN
cnt := 0;
OPEN rscur FOR 'select distinct cl.' || p_field || ' from community_label cl join bkm_relation br on(br.child_id = cl.id)
where br.relation_type = ''2'' and br.parent_id in (
select v.id from v_community_knowledge v
where v.deleted_flag = ''0'' and v.root_id = (
select v2.root_id from v_community_knowledge v2
where v2.id =''' || p_parent_id || ''' ))';
LOOP
FETCH rscur
INTO rsVal;
EXIT WHEN rscur%NOTFOUND;
IF cnt > 0 THEN
retResult := retResult || p_splicing;
END IF;
retResult := retResult || rsVal;
cnt := cnt + 1;
END LOOP;
CLOSE rscur;
return retResult;
EXCEPTION
-- exception handlers begin
WHEN VALUE_ERROR THEN
--
retResult := '';
RETURN retResult;
END F_CONCAT_ROW_COMMUNITY_LABEL;
/**
* example: select F_CONCAT_ROW('id','community_kn_catagory','3',id,',') from community_knowledge;
* 2013/3/11
**/
p_parent_id IN VARCHAR2,
p_splicing IN VARCHAR2)
RETURN VARCHAR2 IS
retResult VARCHAR2(32767);
TYPE cur_type IS REF CURSOR;
rscur cur_type;
rsVal VARCHAR2(2000);
cnt INTEGER;
BEGIN
cnt := 0;
OPEN rscur FOR 'select distinct cl.' || p_field || ' from community_label cl join bkm_relation br on(br.child_id = cl.id)
where br.relation_type = ''2'' and br.parent_id in (
select v.id from v_community_knowledge v
where v.deleted_flag = ''0'' and v.root_id = (
select v2.root_id from v_community_knowledge v2
where v2.id =''' || p_parent_id || ''' ))';
LOOP
FETCH rscur
INTO rsVal;
EXIT WHEN rscur%NOTFOUND;
IF cnt > 0 THEN
retResult := retResult || p_splicing;
END IF;
retResult := retResult || rsVal;
cnt := cnt + 1;
END LOOP;
CLOSE rscur;
return retResult;
EXCEPTION
-- exception handlers begin
WHEN VALUE_ERROR THEN
--
retResult := '';
RETURN retResult;
END F_CONCAT_ROW_COMMUNITY_LABEL;
/**
* example: select F_CONCAT_ROW('id','community_kn_catagory','3',id,',') from community_knowledge;
* 2013/3/11
**/