oracle 使用 find in set 函式

2021-09-02 03:16:13 字數 1234 閱讀 7870

create or replace

function find_in_set(piv_str1 varchar2, piv_str2 varchar2, p_sep varchar2 := ',')

return number is

l_idx number:=0; -- 用於計算piv_str2中分隔符的位置

str varchar2(500); -- 根據分隔符擷取的子字串

piv_str varchar2(500) := piv_str2; -- 將piv_str2賦值給piv_str

res number:=0; -- 返回結果

begin

-- 如果piv_str中沒有分割符,直接判斷piv_str1和piv_str是否相等,相等 res=1

if instr(piv_str, p_sep, 1) = 0 then

if piv_str = piv_str1 then

res:= 1;

end if;

else

-- 迴圈按分隔符擷取piv_str

loop

l_idx := instr(piv_str,p_sep);

-- 當piv_str中還有分隔符時

if l_idx > 0 then

-- 擷取第乙個分隔符前的字段str

str:= substr(piv_str,1,l_idx-1);

-- 判斷 str 和piv_str1 是否相等,相等 res=1 並結束迴圈判斷

if str = piv_str1 then

res:= 1;

exit;

end if;

piv_str := substr(piv_str,l_idx+length(p_sep));

else

-- 當擷取後的piv_str 中不存在分割符時,判斷piv_str和piv_str1是否相等,相等 res=1

if piv_str = piv_str1 then

res:= 1;

end if;

-- 無論最後是否相等,都跳出迴圈

exit;

end if;

end loop;

-- 結束迴圈

end if;

-- 返回res

return res;

end find_in_set;

oracle 游標使用

create or replace function errortyperead return varchar2 is result varchar2 3000 type cursor type is ref cursor tempname varchar2 100 cursor testcur i...

oracle使用小結

1.儲存過程出錯 pls 00103 出現符號 在需要下列之一時 create or replace procedure udf sp tlog add in l id number,in l type number,in b id number,in l desc varchar2 200 in ...

oracle基本使用

ocm oracle 大師認證 ocp oracle 專家認證 oca oracle 初級認證 認證 1千 1.oracle啟動 電腦 管理 服務 oracleorahome90tnslistener oracleservice 你要開啟的資料庫 2.oracle使用者 syssystem scot...