在数据库表c_prodkind里有一个字段codeid,类型为varchar2(6),该字段用于储存车辆编号,储存数据如:0011,0012,00137,0035等,现在需要提取出如11,22,137,35的字符型格式,我用
select to_number(codeid) from c_prodkind;执行时提示oralce抛出 无效数字 的错误;该是怎么写的呢,在转换成数值型后,还要再转成字符型; 或者说有没有其他另外的方法将该列前面的0去掉的呢?
急~~~先谢谢大家啦!

解决方案 »

  1.   

    select to_number(codeid,'99999') from c_prodkind;
    或者
    select substr(codeid,3) from c_prodkind;
      

  2.   


    with t as(
         select '0011' codeid from dual union all
         select '0012' from dual union all
         select '00137' from dual union all
         select '0035' from dual union all
         select '00121' from dual union all
         select '00512' from dual)
    select replace(codeid,'00','') from t--将前面的00替换掉
    select regexp_replace(codeid,'0','') from t--同上
    select regexp_substr(codeid,'[1-9]+') from t--正则表达式,截取除0之外的数字
    /
    11
    12
    137
    35
    121
    512
     
    6 rows selected
      

  3.   

    select ltrim(codeid,'0') from c_prodkind;
      

  4.   

    select ltrim(codeid,'0') from c_prodkind;或者select substr(codeid,3,5) from c_prodkind;或者select replace(codeid,'0','') from c_prodkind;