oracle過濾分割字串自定義函式

2021-06-15 03:15:26 字數 1743 閱讀 4905

該函式實現過濾前後的指定的字串,諸如過濾分隔符等。可用於過濾字串中的逗號分割符。特別說明:substr()函式支援從字串倒數開始讀取,例如:

dbms_output.put_line( substr('hello world',-3,3)); 

執行結果:rld

--過濾字串前後的多疑字元,諸如過濾字串前後的多餘逗號

function fn_dislodgesplitchar(

p_facultylist in varchar2 default '',

p_facultychar in varchar2 default '',

p_facultytype in varchar2 default ''

)

return varchar2

as

v_facultylist varchar2(32767) default '';

v_facultychar varchar2(8000) default '';

v_facultytype varchar2(20) default '';

v_facultylistlength pls_integer default 0;

v_facultycharlength pls_integer default 0;

begin

v_facultylist := trim(p_facultylist);

v_facultychar := trim(p_facultychar);

v_facultytype := trim(p_facultytype);

v_facultylistlength := length(v_facultylist);

v_facultycharlength := length(v_facultychar);

if v_facultytype = 'all' then

v_facultytype := 'leftright';

end if;

if v_facultylistlength > 0 then

if instr(v_facultytype,'left') > 0 and substr(v_facultylist,1,v_facultycharlength) = v_facultychar then

v_facultylist := substr(v_facultylist, -1, v_facultylistlength - v_facultycharlength);

end if;

if instr(v_facultytype,'right') > 0 and substr(v_facultylist,-v_facultycharlength, v_facultycharlength) = v_facultychar then

v_facultylist := substr(v_facultylist,1,v_facultylistlength - v_facultycharlength);

end if;

end if;

return v_facultylist;

end fn_dislodgesplitchar;

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...