从字符串字段中,查找全是数字的记录

有一个字符串字段,里面有的记录是字符,有的是数字,现在需要把全是数字的记录找出来,要做统计。

操作方法如下:

先创建一个和原表结构相同的表:

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;

直接可以得到相事的结果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值