Beside the normal key length issue, as long as you get the datatypes right you should be fine
SQL> create or replace
2 package pkg is
3 function Func1(param1 NUMBER,param2 NUMBER) return varchar2 deterministic;
4 end;
5 /
Package created.
SQL>
SQL>
SQL> create or replace
2 package body pkg is
3 function Func1(param1 NUMBER,param2 NUMBER) return varchar2 deterministic is
4 begin
5 return to_char(param1+param2);
6 end;
7 end;
8 /
Package body created.
SQL>
SQL> drop table t purge;
Table dropped.
SQL> create table t as
2 select * from dba_objects;
Table created.
SQL>
SQL> col x new_value y
SQL> select object_id + data_object_id x from user_objects
2 where object_name = 'T';
X
----------
343008
1 row selected.
SQL>
SQL> create index ix1 on t ( pkg.func1(object_id, data_object_id) );
create index ix1 on t ( pkg.func1(object_id, data_object_id) )
*
ERROR at line 1:
ORA-01450: maximum key length (6398) exceeded
SQL>
SQL> create index ix1 on t ( substr(pkg.func1(object_id, data_object_id),1,30) );
Index created.
SQL>
SQL> set autotrace on explain
SQL> select owner, object_name
2 from t
3 where pkg.func1(object_id, data_object_id) = ltrim('&&y');
old 3: where pkg.func1(object_id, data_object_id) = ltrim('&&y')
new 3: where pkg.func1(object_id, data_object_id) = ltrim(' 343008')
OWNER OBJECT_NAME
------------------------------ ----------------------------------------
MCDONAC T
1 row selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2932790928
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 992 | 55552 | 75 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 992 | 55552 | 75 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IX1 | 397 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("PKG"."FUNC1"("OBJECT_ID","DATA_OBJECT_ID")='343008')
2 - access(SUBSTR("PKG"."FUNC1"("OBJECT_ID","DATA_OBJECT_ID"),1,30)='343008')
SQL>
SQL> select owner, object_name
2 from t
3 where substr(pkg.func1(object_id, data_object_id),1,30) = ltrim('&&y');
old 3: where substr(pkg.func1(object_id, data_object_id),1,30) = ltrim('&&y')
new 3: where substr(pkg.func1(object_id, data_object_id),1,30) = ltrim(' 343008')
OWNER OBJECT_NAME
------------------------------ ----------------------------------------
MCDONAC T
1 row selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2932790928
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 992 | 48608 | 75 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 992 | 48608 | 75 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IX1 | 397 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(SUBSTR("PKG"."FUNC1"("OBJECT_ID","DATA_OBJECT_ID"),1,30)='343008')
SQL>
SQL>