- 在包頭裡定義TYPE SPLIT_TBL IS TABLE OF VARCHAR2(32767);
- 在包頭裡定義
- FUNCTION SPLIT(
- VLIST IN VARCHAR2,
- VDEL IN VARCHAR2:=','
- )RETURN SPLIT_TBL PIPELINED
- IS
- VIDX PLS_INTEGER;
- VVLIST VARCHAR2(32767):=VLIST;
- BEGIN
- LOOP
- VIDX := INSTR(VVLIST,VDEL);
- IF VIDX > 0 THEN
- PIPE ROW(SUBSTR(VVLIST,1,VIDX-1));
- VVLIST:= SUBSTR(VVLIST,VIDX+LENGTH(VDEL));
- ELSE
- PIPE ROW(VVLIST);
- EXIT;
- END IF;
- END LOOP;
- RETURN;
- END SPLIT;
- 具體應用
- SELECT DECODE(POSITION,0,POST_STR,SUBSTR(POST_STR,1,POSITION-1)) AS POST_ID,
- B.USER_ID, B.USER_NM
- FROM (SELECT COLUMN_VALUE AS POST_STR,INSTR(COLUMN_VALUE,',') AS POSITION,INSTR(COLUMN_VALUE,' ') AS POSITION2
- FROM
- TABLE(PCK_ICS.SPLIT(SUBSTR('0001;0002;',0,LENGTH('0001;0002;')-1),';'))
- ) A,TBL_USER B,TBL_POSITION C
- WHERE DECODE(POSITION,0,POST_STR,SUBSTR(POST_STR,1,POSITION-1))=C.POST_ID
- AND B.USER_ID=C.USER_ID
將字符串利用分隔符轉成表格
最新推荐文章于 2023-05-25 13:35:25 发布