当前位置:Gxlcms > 数据库问题 > ORACLE-012:oracle中纯数字的varchar2类型和number类型自动转换

ORACLE-012:oracle中纯数字的varchar2类型和number类型自动转换

时间:2021-07-01 10:21:17 帮助过:2人阅读

使用过一个关联查询,两个表的字段定义了不同的类型。一个字段是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-012:oracle中纯数字的varchar2类型和number类型自动转换

标签:

人气教程排行