Find out if a string contains only ASCII characters

后端 未结 3 1446
傲寒
傲寒 2020-12-06 15:07

I need to know whether a string contains only ASCII characters. So far I use this REGEX:

DECLARE
    str VARCHAR2(100) := \'xyz\';
BEGIN
    IF REGEXP_LIKE(s         


        
3条回答
  •  旧时难觅i
    2020-12-06 15:29

    ASCII function with upper limit of 127 may be used :

    declare
        str nvarchar2(100) := '\xyz~*-=)(/&%+$#£>|"éß';
        a   nvarchar2(1);
        b   number := 0;
    begin
        for i in 1..length(str)
        loop                 
          a := substrc(str,i,1);
          b := greatest(ascii(a),b);      
        end loop;
    
        if b < 128 then  
         dbms_output.put_line('String is composed of Pure ASCII characters');
        else
         dbms_output.put_line('String has non-ASCII characters');      
        end if; 
    end;
    

提交回复
热议问题