文章目录

      最近有个需求,sql如下:

select 
	case 
		when score < 60  then  60  
		else '优秀' end  
from stuent

     但是运行的时候报错了:ERROR: invalid input syntax for type numeric:'优秀'
      百度说:数据类型不符。
      仔细想一下, 60是int,优秀是string,确实类型不符。
      sql修改如下:

select 
	case 
		when score < 60  then '' || 60  
		else '优秀' end  
from stuent

  这样就都是string了,就不报错了。

把结果扩展一下

      其实这个报错不只case when会报,其他语句也会报这个错。原因都是类型不符,只要抓住这个,去排错就行了。

相关文章:

  • 2021-08-23
  • 2021-09-10
  • 2021-06-28
  • 2021-05-13
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-12-09
相关资源
相似解决方案