有一个字符串字段,里面有的记录是字符,有的是数字,现在需要把全是数字的记录找出来,要做统计。
操作方法如下:
先创建一个和原表结构相同的表:
create table temp as select * from s_permission_area where 1=0;
新建的表中是不能有数据的。因此用 1=0 来做限制。
创建一个过程:
create or replace procedure pro_find_number is
cursor cur_temp is
select * from s_permission_area t;
c_temp cur_temp%rowtype;
m_id number(18);
begin
m_id := 0;
open cur_temp;
loop
fetch cur_temp
into c_temp;
exit when cur_temp%notfound;
begin
m_id := to_number(c_temp.code);
execute immediate 'insert into temp select * from s_permission_area where code = :code'
using c_temp.code;
exception
when others then
null;
end;
end loop;
close cur_temp;
commit;
exception
when others then
rollback;
raise;
end pro_find_number;
运行完成时,合格数据全部写到临时表中。
select t.*, t.rowid from temp t
就可以看到全部的数据。
用完后,可以
truncate table temp;
drop table temp;
还有一种非常简单的方法:
select * from s_permission_area where trim(translate(code,'0123456789',' ')) is null;
直接可以得到相事的结果。