oracle實現split函式

2021-07-10 11:16:36 字數 1609 閱讀 5311

oracle資料庫中某乙個字段可能存在以某些特殊符號隔開的字段,我們在查詢使用的時候往往需要將這些欄位spilt開

但是oracle沒有這個函式,網上搜尋了一下,找了乙個可以使用的函式

下面直接上指令碼:

1.先建立乙個type

create or replace type obj_target as object

(obj_id    varchar2(50),

obj_value varchar2(128)

);2.type對映table

create or replace type tabstr_t as table of varchar2(4000);

create or replace type typ_array_target as table of obj_target;

3.建立函式

create or replace function fun_split (

p_str in varchar2,

p_sep in varchar2 default ','

)return tabstr_t

isl_str long := p_str || p_sep;

l_tabstr tabstr_t := tabstr_t();

begin

while l_str is not null loop

l_tabstr.extend(1);

l_tabstr(l_tabstr.count) := rtrim(substr(

l_str,1,instr(l_str,p_sep)),p_sep);

l_str := substr(l_str,instr(l_str,p_sep)+1);

end loop;

return l_tabstr;

end;

4.使用

select column_value as val from table(fun_split(c.waybill_no,' '));

函式中使用

create or replace function fun_report_dealdetailed return typ_array_target

pipelined is

cursor cur is select id,waybill_no from t_tmk_order_track t where t.follow_result ='success';

r_target_data obj_target := obj_target(null, null);

begin

for c in cur loop

r_target_data.obj_id := c.id;

for c1 in (select column_value as val from table(fun_split(c.waybill_no,' ')))

loop

r_target_data.obj_value := c1.val;

pipe row(r_target_data);

end loop;

end loop;

return;

end fun_report_dealdetailed;

Oracle 實現 split 函式 返回陣列)

功能描述 用指定分隔符切割輸入的字串,返回一維陣列,每個陣列元素為乙個子串。源 create or replace type ty str split is table of varchar2 4000 create or replace function fn split p str in var...

split 函式實現

split函式實現 ss axx bv ctt dff result def split 1 ss,a,times len ss i 0n 0 while len ss 0 and iand nif ss i i len a a print i i print 之前的ss ss print resu...

c 實現split函式

今天工作因原因,需要實現乙個split的功能,以前也做過,但一直沒有把他記下來,所以又重新寫了一次。這次做個筆記以備後用,各位感興趣也可以直接拿來用過。例子 乙個這樣的字串 123,456,789,0 把他擷取成這樣的字串陣列 123 456 789 0 眾所周知c 預設沒有提供這樣功能的函式,下面...