日期:2014-05-16 浏览次数:20351 次
create or replace function VIEW_PATIENT_SYNDROME_2(v_id_symptom_hospital in varchar2) return varchar2 is --返回症候群名字形如:发热呼吸道1,神经中枢1 v_name_syndrome varchar2(1024) := ''; --临时存储症候群名字 v_name_tmp varchar2(40) := ''; --症候群编码 v_code_syndrome varchar2(1024); --循环累加计数 v_count binary_integer := 1; --症候群总数 v_count_syndrome number; --症候群子表id v_id_syndrome varchar2(40); begin --查询一个病例对应症候群数量 select count(*) into v_count_syndrome from csmw_syndrome_hospital csh where csh.idreference_syndrome = v_id_symptom_hospital; --迭代症候群 while v_count <= v_count_syndrome loop --症候群子表id_syndrome写入v_id_syndrome select id_syndrome into v_id_syndrome from (select rownum, nvl(csh.id_syndrome, '') as id_syndrome from csmw_syndrome_hospital csh where rownum <= v_count and csh.idreference_syndrome = v_id_symptom_hospital order by rownum desc) tmp where rownum = 1; --根据症候群子表id_syndrome取出症状编码写入v_code_syndrome select csh.code_syndrome into v_code_syndrome from csmw_syndrome_hospital csh where csh.id_syndrome = v_id_syndrome; --根据症状编码code_syndrome获取症状名称写入v_name_tmp select cms.name_syndrome into v_name_tmp from csmw_management_syndrome cms where cms.code_syndrome = v_code_syndrome; --拼接症状名称 v_name_syndrome := v_name_syndrome || ',' || v_name_tmp; v_count := v_count + 1; end loop; --去除左边的',' select ltrim(v_name_syndrome, ',') into v_name_syndrome from dual; return v_name_syndrome; end VIEW_PATIENT_SYNDROME_2;