将String转换为int并在Where子句中使用

时间:2013-10-29 09:24:44

标签: sql oracle

如何转换字符串字段并用于Where子句。这样的异常请帮助找到错误的东西。

select * from student 
where (cast (nvl(linerevnum,'0') as int)) = 1

linerevnum是varchar2

例外: 无效的号码

1 个答案:

答案 0 :(得分:6)

仅在数字时比较

select * from student 
where 
  (
  case when ISNUMERIC( linerevnum ) 
  then cast (linerevnum as int)
  else null
  end  ) = 1

或简单:

select * from student 
linerevnum = '1'