Welcome 微信登录

首页 / 数据库 / MySQL / Oracle中纯数字的varchar2类型和number类型自动转换

使用过一个关联查询,两个表的字段定义了不同的类型。一个字段是varchar2类型,另一个字段是number类型,内容如下:"00187"和187。在使用中发现会自动将varchar2类型转换为number,即187和187。效果与to_number()一样。专门写了两个sql测试了下,如下:select
case when "0110" = 110 then
  "true"
else
  "false"
 end
 from dual;
select
case when to_number("0110") = to_number(110) then
  "true"
else
  "false"
 end
 from dual;结果都是true。不过为了保险起见还是用to_number()进行转换更好一些。更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址