ORACLE: PL/SQL 自定义函数判断字符串是否存在汉字
ORACLE PL/SQL 自定义函数判断字符串是否存在汉字。
oracle环境:19C
Character Sets
Character size: 4 byte(s)
CharSetID: 873
NCharSetID: 2000
Unicode Support: True
NLS_LANG: SIMPLIFIED CHINESE_CHINA.ZHS16GBK
NLS_NCHAR_CHARACTERSET: AL16UTF16
NLS_CHARACTERSET: AL32UTF8
create or replace function f_exists_hanzi(p_string in varchar2) return varchar2 is
v_result varchar2(4);
--v_result: 返回是否存在汉字标志(Y/N)。 Y: 表示存在汉字 , N: 表示不存在汉字
v_tmp varchar2(32000);
v_word varchar2(4);
begin
V_RESULT :='N';
-- 14989440 ~ 15318693 AS "一~龥"
if trim( p_string) is not null then
v_tmp :=p_string;
for i in 1..length(p_string) loop
v_word := subStr(v_tmp,1,1) ;
if ( ascii(v_word) between 14989440 and 15318693 ) then
v_result :='Y';
exit;
else
v_tmp :=substr(v_tmp,2,length(v_tmp));
end if;
end loop;
end if;
<<return_result>>
return(v_Result);
end f_exists_hanzi;
例子:
select f_exists_hanzi('aBC您DE'),f_exists_hanzi('Connector\LJL01\Φ50.8X1.0\304\Satin好') "英语" , f_EXISTS_HANZI('') AS "空值" FROM DUAL;