Oracle多行轉一行

xypincle發表於2017-02-19

  1. CREATE OR REPLACE FUNCTION comm.f_get_diagnosisdesc(v_patient_id diagnosis.patient_id%type,v_visit_id diagnosis.visit_id%TYPE,v_diagnosis_type diagnosis.diagnosis_type%type)
  2. --將診斷表多行的值轉換為一行 鍾思平 20140610 南昌三三四醫院
  3. RETURN VARCHAR2
  4. IS
  5. v_diagnosis_desc VARCHAR2(200) ;
  6. BEGIN
  7. FOR cur IN (SELECT diagnosis_desc from medrec.diagnosis WHERE patient_id = v_patient_id AND visit_id = v_visit_id AND diagnosis_type = v_diagnosis_type )
  8. LOOP
  9. v_diagnosis_desc := v_diagnosis_desc||cur.diagnosis_desc||' ; ';
  10. END LOOP;
  11. v_diagnosis_desc := Trim(v_diagnosis_desc) ;
  12. RETURN v_diagnosis_desc ;
  13. END f_get_diagnosisdesc ;

  14. --建立同義詞
  15. create or replace public synonym f_get_diagnosisdesc for comm.f_get_diagnosisdesc ;
  16. commit;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28878983/viewspace-2133883/,如需轉載,請註明出處,否則將追究法律責任。

相關文章