Oracle 字串分割 Split

2021-09-01 18:14:20 字數 1411 閱讀 3155

廢話不多說直接上**

一、建立陣列型別

create or replace type t_ret_table is table of varchar2(512)
二、建立字串分割函式

create or replace function f_split_string(as_str   varchar2,

as_split varchar2)

return t_ret_table is

-- author : guomm

-- created : 2013/5/22 13:38:46

-- purpose : 字串分割

-- params

-- as_str : 要處理的字串

-- as_split :字串分割符

v_out t_ret_table;

v_tmp varchar2(4000);

v_element varchar2(4000);

begin

v_tmp := as_str;

v_out := t_ret_table();

--如果存在匹配的分割符

while instr(v_tmp, as_split) > 0 loop

v_element := substr(v_tmp, 1, instr(v_tmp, as_split) - 1);

v_tmp := substr(v_tmp,

instr(v_tmp, as_split) + length(as_split),

length(v_tmp));

v_out.extend(1);

v_out(v_out.count) := v_element;

end loop;

if v_tmp is not null then

v_out.extend(1);

v_out(v_out.count) := v_tmp;

end if;

return v_out;

end f_split_string;

ok,到此功能已經實現,

三、呼叫

select * from table(f_split_string('1,2,3,4,5,6',','))

declare

v_array t_ret_table;

begin

v_array := f_split_string('1,2,3,4,5,6',',');

for i in 1..v_array.count loop

dbms_output.put_line(v_array(i));

end loop;

end;

Oracle 分割字串

第一種方式建立函式 create or replace type str split is table of varchar2 4000 create or replace function splitstr p string in varchar2,p delimiter in varchar2 ...

Oracle 字串分割 Split

一 建立陣列型別 sql create orreplace type t ret table is table of varchar2 512 二 建立字串分割函式 sql create orreplace function f split string as str varchar2,as spl...

Oracle字串分割Split

一 建立陣列型別 sql create orreplace type t ret table is table of nvarchar2 1000 二 建立字串分割函式 sql create or replace function f split string as str nvarchar2,as...