3

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

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

linerevnum 是 varchar2

例外:无效号码

4

1 回答 1

7

仅在为数字时比较

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

或简单:

select * from student 
linerevnum = '1'
于 2013-10-29T09:30:14.950 回答