SQL_将对应逗号分隔的code码转为对应中文

阅读更多

 

由于业务需要,某些字段需要存储多个数值,是以code码逗号分隔存储的,而页面需要展示对应的中文,中文又存在系统码表内,所以需要将逗号分隔的code转为逗号分隔的中文。

 

CREATE OR REPLACE FUNCTION IDSPLITROMLIST
(
  v_list_in IN VARCHAR2,
  v_separtor IN CHAR
)
RETURN SPLIT_ID_TAB PIPELINED
AS
   v_SUB VARCHAR2(100);
   v_POS NUMBER(10,0);
   v_list VARCHAR2(4000);
   v_id_table SPLIT_ID;
BEGIN
   v_list := v_list_in;
   v_POS := INSTR(v_list, v_separtor);

   WHILE v_POS > 0
   LOOP
      BEGIN
         v_SUB := SUBSTR(v_list, 1, v_POS - 1);

         v_id_table := SPLIT_ID(v_SUB);
         PIPE ROW(v_id_table);

         v_list := SUBSTR(v_list, v_POS + 1, LENGTHB(v_list) - v_POS);

         v_POS := INSTR(v_list, v_separtor);

      END;
   END LOOP;

   v_list := LTRIM(RTRIM(v_list));

   IF length(v_list) > 0 THEN
     v_id_table := SPLIT_ID(v_list);
     PIPE ROW(v_id_table);
   END IF;

END;

 

使用方法:

(select wm_concat(to_char(tt2.PARMVALUE))

from TPTAEXGS tt2 where 1=1 

and parmtype = 'STAGEUNIT'

and tt2.PARMNAME in

(select * from table(idsplitromlist(t.STAGEUNITS, ',')))) STAGEUNITSNAME

from BPSSRRSM t

你可能感兴趣的:(SQL)