1
SQL> select o.no from Org_Table o where o.no=0080000;   
NO
---
00080000   

SQL> select o.no from Org_Table o where o.no='0080000';  
NO
---

SQL> select o.no from Org_Table o where o.no='00080000';   
NO
---
00080000  

为什么第一个结果和第二个不一样?</p>

4

1 回答 1

7

Check execution plan of your query with filter predicates. This is what I see (assuming no field is varchar2):

Execution Plan
----------------------------------------------------------
Plan hash value: 2153619298

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |  2002 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |     1 |  2002 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(TO_NUMBER("NO")=0080000)

Notice 1 - filter(TO_NUMBER("NO")=0080000) - an implicit type conversion. Your data is compared as number, in which case 0080000 equals 80000. However, in the second case it is compared as strings (1 - filter("NO"='0080000')), which are in this case different.

于 2013-07-10T03:34:14.963 回答