Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我遇到了一条 SQL 语句,其中一个条件是comp_cd > to_char('0000000000','9999999999').
comp_cd > to_char('0000000000','9999999999')
运行select to_char('0000000000','9999999999') from dual我得到结果“0”。
select to_char('0000000000','9999999999') from dual
有没有人遇到过这个?
该函数TO_CHAR需要一个 NUMBER 或 DATE 作为它的第一个参数,但您提供的是一个字符串 ( '0000000000') 。
TO_CHAR
'0000000000'
因此,Oracle 使用隐式转换先将其转换为 NUMBER;'0000000000'转换为数字0。
0
然后,TO_CHAR使用格式模型转换0回字符串。'9999999999'这应该导致字符串:
'9999999999'
' 0'
最后:
comp_cd > ' 0'
将在两个字符串之间进行词汇(字母)比较。