1. 程式人生 > >ORACLE中between-and 無效數字

ORACLE中between-and 無效數字

1.當需要用到between-and的欄位是varchar2型別時,放在where 之後會報錯:

ORA-01722:無效數字 select  * from table_name  where num between 15and 17;

select * from ( select to_number(num) asnum   from table_name  )  where num between 15and 17;

解決在不改變表結構的情況下,只能建立臨時表存放資料,操作臨時表;

2. 放在select-from 中case-when,無問題,且不需要to_number轉換: select (case when num between 0 and 10 then 'A' 

when  num between 11 and 20 then 'B'

else 'C' end )   from table_name;