create function num_asc(p_col in varchar2)
return number
as
a number;
begin
a:=to_number(p_col);
return a;
exception
when others then
return ascii(p_col)+99999999999;
end;
/
select * from tab order by num_asc(col);

解决方案 »

  1.   

    如果你的字段宽度是3,那么按以下方法,如果是4,或5等等,只要改动一下我的SQL语句即可
    如果是长度为几十,那就麻烦。
    select * from table order by decode(length(字段),3,字段,2,'0'||字段,'00'||字段)
      

  2.   

    如果数据中没有'123ab'这种字符在数字后面的情况的话,可以这样写SQL> select name from tb;NAME
    ----------
    asd
    123
    12
    23
    3
    a3已选择6行。SQL> select name from tb where ascII(name) between
      2  
    SQL> select ascII(1),ascII(9),ascII(0) from dual;  ASCII(1)   ASCII(9)   ASCII(0)
    ---------- ---------- ----------
            49         57         48SQL> select name from tb where ascII(name) between 48 and 57
      2  union all
      3  select name from tb where ascII(name)<48 or ascII(name)>57 order by name;NAME
    ----------
    12
    123
    23
    3
    a3
    asd已选择6行。SQL>
      

  3.   

    create function num_asc(p_col in varchar2)
    return number
    as
    a number;
    begin
    a:=to_number(p_col);
    return a;
    exception
    when others then
    return ascii(p_col)+99999999999;
    end;
    /
    这些写在哪里?是程序页面上,还是oracle里?