pl sql中實現字串分割

2022-05-05 22:45:18 字數 1392 閱讀 4572

在網上找了很久,看到有幾種實現方法,其中以下面的這種方法最為適合,

/**用pipe函式實現字串分割

**/create or replace type ty_str_split is table of varchar2 (20);

/create or replace function fn_split (p_str in varchar2, p_delimiter in varchar2)

return ty_str_split pipelined

isj int := 0;

i int := 1;

len int := 0;

len1 int := 0;

str varchar2 (4000);

begin

len := length (p_str);

len1 := length (p_delimiter);

while j < len loop

j := instr (p_str, p_delimiter, i);

if j = 0 then

j := len;

str := substr (p_str, i);

pipe row (str);

if i >= len then

exit;

end if;

else

str := substr (p_str, i, j - i);

i := j + len1;

pipe row (str);

end if;

end loop;

return;

end fn_split;

/--測試:

--1直接在sql中呼叫

select fn_split ('1;;12;;123;;1234;;12345', ';;') from dual;

--2生成table

select * from table (fn_split ('1;;12;;123;;1234;;12345', ';;'));

--3在儲存過程中使用的方法

create or replace procedure test(str varchar2,splitchar varchar2)

iscstr ty_str_split;

i number;

begin

select fn_split (str,splitchar) into cstr from dual;

for i in cstr.first()..cstr.last() loop

dbms_output.put_line(cstr(i));

end loop;

end;

/exec test('fadsffadsf','a')

分割字串 FanucKarel中實現字串分割

分享與快樂同在!最近有小夥伴詢問如何按指定分隔符分割字串,在karel中並沒有按字元分割的內建程式供我們使用,那麼我們就來實現這個功能!在專案中,經常會在字串中提取資料,比如機械人與相機使用tcp ip通訊 字串文字中資料提取等等。如何按字元將乙個字串資料拆分為多個字串,最終將字串轉換為其他資料型別...

C 中實現字串分割split

c 預設沒有提供字串分割函式,若要對字串進行分割則需自己處理。首先想到的就是使用string find函式查詢到指定的分隔符,然後通過substr擷取子串,來實現字串的分割。更方便的方式 c 提供了從輸入流中獲取子串的getline,配合istringstream,即能方便地實現字串的分割操作 以提...

c 實現字串分割

類似於python,shell,perl等語言都提供了方便的split 介面,用以分割字串。c c需要自己寫,這樣耗時耗力還沒效率,沒保障的方法,當然是需要避免的。又是強大的boost庫提供了方便。h檔案 ifndef dirfileopt hhhh define dirfileopt hhhh i...