Home  >  Article  >  Database  >  Oracle中纯数字的varchar2类型和number类型自动转换

Oracle中纯数字的varchar2类型和number类型自动转换

WBOY
WBOYOriginal
2016-06-07 15:21:192332browse

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()进行转换更好一些。

本文永久更新链接地址

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn