Oracle SQL判断字符串是否在目标字符串中的函数
2018-01-21 12:56
381 查看
转自:http://dacoolbaby.iteye.com/blog/1772156
根据需求,写了一段方法。
用于识别以下的情况:
判断 字符串A 在用逗号分隔的字符串B中是否存在
如:
v_str_a = aa ;
v_str_b= aa,bb,dd,cc ;
如上,就返回Y,否则返回N。
添加了一些校验。
以后可以根据需求,按照指定的分隔符,提取字符串。
毕竟Oracle的字符串解析比较麻烦,能封装就封装。
根据需求,写了一段方法。
用于识别以下的情况:
判断 字符串A 在用逗号分隔的字符串B中是否存在
如:
v_str_a = aa ;
v_str_b= aa,bb,dd,cc ;
如上,就返回Y,否则返回N。
添加了一些校验。
以后可以根据需求,按照指定的分隔符,提取字符串。
毕竟Oracle的字符串解析比较麻烦,能封装就封装。
1 create or replace function func_str_inArray(p_target varchar2, 2 p_str_array varchar2) 3 return varchar2 is 4 5 v_flag varchar2(1); 6 v_comma_loc int; 7 v_cut_string varchar2(300); 8 v_rest_string varchar2(2000); 9 begin 10 ------------------------ 11 --p_target 不能包含","!!!注意!! 12 --info:这个函数用于识别目标字符串,是否在一串用“,”分开的字符串内 13 ------------------------ 14 v_flag := 'N'; 15 v_comma_loc := instr(p_str_array, ','); 16 17 --如果是对比字符串是空,则返回false 18 if nvl(p_str_array, '') = '' then 19 return 'N'; 20 end if; 21 --如果没有逗号,直接比较 22 if length(p_str_array) > 0 and v_comma_loc = 0 then 23 if p_target = p_str_array then 24 return 'Y'; 25 else 26 return 'N'; 27 end if; 28 end if; 29 30 v_rest_string := p_str_array; 31 32 while v_comma_loc > 0 loop 33 v_cut_string := substr(v_rest_string, 0, v_comma_loc - 1); 34 v_rest_string := substr(v_rest_string, 35 v_comma_loc + 1, 36 length(v_rest_string) - 1); 37 38 if p_target = v_cut_string then 39 v_flag := 'Y'; 40 end if; 41 42 v_comma_loc := instr(v_rest_string, ','); 43 44 if v_comma_loc = 0 and length(v_rest_string) > 0 then 45 if p_target = v_rest_string then 46 v_flag := 'Y'; 47 end if; 48 end if; 49 50 end loop; 51 52 return v_flag; 53 54 end;
相关文章推荐
- 用oracle函数判断字符串中是否包含中文
- oracle判断是否为数字或数字型字符串(sqlserver isnumeric)
- java python oracle判断字符串是否为数字的函数
- oracle的常用函数 instr() 和substr()函数 博客分类: oracle 在Oracle中 可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符。 在一个
- oracle 函数判断字符串是否包含图片格式的实例代码
- t-sql判断一个字符串是否为bigint的函数(全角数字需要判断为不合格)
- 在sql 数据库中,用脚来判断字符串是否为数字的函数
- t-sql判断一个字符串是否为bigint的函数(全角数字需要判断为不合格)
- 用oracle函数判断字符串中是否包含中文
- t-sql判断一个字符串是否为bigint的函数(全角数字需要判断为不合格)
- oracle中判断一个字符串是否全部为数字的函数-translate
- oracle 函数判断字符串是否包含图片格式
- oracle中判断一个字符串是否全部为数字的函数
- oracle 身份证 校验位 判断字符串是否为数字函数
- oracle中判断一个字符串是否全部为数字的函数
- 在delphi中判断字符串是否数字,以及精度处理函数
- 1.8 利用已知函数判断字符串是否为另一字符串的子串
- 使用CString 的 SpanIncluding 函数判断字符串是否全为数字
- 写一个函数判断两个字符串是否是变位词
- pl/sql 函数之判断多个分割的数字是否在某个范围