oracle怎么在字符字段中查出只包含数字的数据?

2025-04-30 00:57:51
推荐回答(1个)
回答1:

declare   v_length  number default 0;  

t_sum    number default 0; 

t_num    number default 0;  

t_is_num number default 0;  

v_str    TMP_XYX26.T2%type;   

cursor t_cur is select t2 from TMP_XYX26 where regexp_substr(t2, '[0-9]+') is not null; 

begin  open t_cur;  

loop    fetch t_cur      into v_str;    

exit when t_cur%notfound;    t_sum := 0;    

select length(v_str) into v_length from dual;    

for i in 1 .. v_length loop    select ascii(substr(v_str, i, 1)) into t_is_num from dual; 

if t_is_num between 48 and 57 then   select substr(v_str, i, 1) into t_num from dual;       

t_sum := t_sum + t_num;            

else null;      

end if;         

end loop;      

dbms_output.put_line;

end loop; 

close t_cur;

end;