impossible to comment.
need a better, more complete example.
for I can come with examples such that
a) yes, it would be useful
b) no, it would not be useful
c) it really would not matter one way or the other
there are only two answers to all questions!!!
answer 1: "why"
answer 2: "it depends"
ops$tkyte@ORA10GR2> create table a ( x number constraint x_unique unique, col1 number constraint col1_unique unique );
Table created.
ops$tkyte@ORA10GR2> create table b ( y number constraint y_unique unique, col2 varchar2(20) constraint col2_unique unique );
Table created.
Suppose the query is:
ops$tkyte@ORA10GR2> set autotrace traceonly explain
ops$tkyte@ORA10GR2> select *
2 from a, b
3 where a.x = 10
4 and b.y = 11
5 and a.col1 = b.col2
6 /
Execution Plan
----------------------------------------------------------
Plan hash value: 2215097824
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 51 | 2 (0)|
| 1 | NESTED LOOPS | | 1 | 51 | 2 (0)|
| 2 | TABLE ACCESS BY INDEX ROWID| B | 1 | 25 | 1 (0)|
|* 3 | INDEX UNIQUE SCAN | Y_UNIQUE | 1 | | 1 (0)|
|* 4 | TABLE ACCESS BY INDEX ROWID| A | 1 | 26 | 1 (0)|
|* 5 | INDEX UNIQUE SCAN | X_UNIQUE | 1 | | 0 (0)|
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("B"."Y"=11)
4 - filter("A"."COL1"=TO_NUMBER("B"."COL2"))
5 - access("A"."X"=10)
<b>Unlikely to consider an index on COL1/COL2 - when you have such nice alternatives on X and Y..
Or maybe you do this:</b>
ops$tkyte@ORA10GR2> select *
2 from a, b
3 where a.col1 = b.col2
4 and b.y = 5
5 /
Execution Plan
----------------------------------------------------------
Plan hash value: 2711371623
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 51 | 3 (0
| 1 | NESTED LOOPS | | 1 | 51 | 3 (0
| 2 | TABLE ACCESS BY INDEX ROWID| B | 1 | 25 | 2 (0
|* 3 | INDEX UNIQUE SCAN | Y_UNIQUE | 1 | | 1 (0
| 4 | TABLE ACCESS BY INDEX ROWID| A | 1 | 26 | 1 (0
|* 5 | INDEX UNIQUE SCAN | COL1_UNIQUE | 1 | | 0 (0
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("B"."Y"=5)
5 - access("A"."COL1"=TO_NUMBER("B"."COL2"))
<b>and since Oracle converts implicitly the string to a number, the existing index on A.COL1 is naturally used...
However, if you:</b>
ops$tkyte@ORA10GR2> select *
2 from a, b
3 where a.col1 = b.col2
4 and a.x = 5
5 /
Execution Plan
----------------------------------------------------------
Plan hash value: 18212380
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 51 | 30850 (1)|
| 1 | NESTED LOOPS | | 1 | 51 | 30850 (1)|
| 2 | TABLE ACCESS BY INDEX ROWID| A | 1 | 26 | 2 (0)|
|* 3 | INDEX UNIQUE SCAN | X_UNIQUE | 1 | | 1 (0)|
|* 4 | TABLE ACCESS FULL | B | 1 | 25 | 30848 (1)|
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("A"."X"=5)
4 - filter("A"."COL1"=TO_NUMBER("B"."COL2"))
<b>then EITHER:</b>
ops$tkyte@ORA10GR2> select *
2 from a, b
3 where to_char(a.col1) = b.col2
4 and a.x = 5
5 /
Execution Plan
----------------------------------------------------------
Plan hash value: 950355497
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 51 | 3 (0
| 1 | NESTED LOOPS | | 1 | 51 | 3 (0
| 2 | TABLE ACCESS BY INDEX ROWID| A | 1 | 26 | 2 (0
|* 3 | INDEX UNIQUE SCAN | X_UNIQUE | 1 | | 1 (0
| 4 | TABLE ACCESS BY INDEX ROWID| B | 1 | 25 | 1 (0
|* 5 | INDEX UNIQUE SCAN | COL2_UNIQUE | 1 | | 0 (0
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("A"."X"=5)
5 - access("B"."COL2"=TO_CHAR("A"."COL1"))
<b>an explicit conversion of the number to a string could be used - BUT - it might change the answer!!! since you can store a number in a string using many many many representations:
0001
01
1
1.00000
+1
1e-0
those are all the number "1" of course if you to_number them. However a to_char of a number 1 will result in "one string" and that one string won't match them all
But of course, if you can create a function based index on B.COL2 like this:
create index I on b(to_number(col2))
that implies col2 is REALLY A NUMBER
and you have made one of the the worst mistakes you could ever make in your life - putting a number in a string.
And the solution to that of course is
FIX IT</b>