Oracle将以逗号分隔的数字字符串根据字典表转换为中文字符串

CREATE OR REPLACE FUNCTION FN_GET_STATUS_STR(P_STR IN VARCHAR2)
  RETURN VARCHAR2 AS
  LSTR   VARCHAR2(1000) DEFAULT P_STR || ',';
  RETSTR VARCHAR2(1000) DEFAULT NULL;
  TMPSTR VARCHAR2(50) DEFAULT NULL;
  LREC   NUMBER;
  LNO    NUMBER;
  LID    NUMBER;
BEGIN
  LOOP
    LNO := INSTR(LSTR, ',');
    EXIT WHEN(NVL(LNO, 0) = 0);
    LID := NVL(TO_NUMBER(LTRIM(RTRIM(SUBSTR(LSTR, 1, LNO - 1))), '999'), 0);
    IF LID > 0 THEN
      SELECT COUNT(*)
        INTO LREC
        FROM RESPONSESTATUS T
       WHERE RESPONSESTATUS_ID = LID;
      IF LREC > 0 THEN
        SELECT RESPONSESTATUS
          INTO TMPSTR
          FROM RESPONSESTATUS T
         WHERE RESPONSESTATUS_ID = LID;
        IF TMPSTR IS NOT NULL THEN
          IF RETSTR IS NULL THEN
            RETSTR := TMPSTR;
          ELSE
            RETSTR := RETSTR || ',' || TMPSTR;
          END IF;
        END IF;
      END IF;
    END IF;
    LSTR := SUBSTR(LSTR, LNO + 1);
  END LOOP;
  RETURN RETSTR;
END;

你可能感兴趣的:(Oracle)