DB/Oracle
Oracle Split Function 구현
망할고양이
2017. 6. 20. 17:43
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | CREATE OR REPLACE FUNCTION SPLIT(P_INPUT_LIST VARCHAR2, P_RET_THIS_ONE NUMBER, P_DELIMITER VARCHAR2) RETURN VARCHAR2 /*****************************************************************************************/ /* P_DELIMITER로 구분된 문자열을 구분하여 해당 INDEX의 값을 리턴하는 함수 /* /* CREATE BY D.CAT /*****************************************************************************************/ IS V_LIST VARCHAR2(32767) := P_DELIMITER || P_INPUT_LIST; START_POSITION NUMBER; END_POSITION NUMBER; BEGIN START_POSITION := INSTR(V_LIST, P_DELIMITER, 1, P_RET_THIS_ONE); IF START_POSITION > 0 THEN END_POSITION := INSTR( V_LIST, P_DELIMITER, 1, P_RET_THIS_ONE + 1); IF END_POSITION = 0 THEN END_POSITION := LENGTH(V_LIST) + 1; END IF; RETURN(SUBSTR(V_LIST, START_POSITION + 1, END_POSITION - START_POSITION - 1)); ELSE RETURN NULL; END IF; END SPLIT; | cs |