CREATE OR REPLACE function ind_pos (tab in varchar2, col in varchar2, ind_no in number) return varchar2 is
CURSOR MY_IND IS select index_name IND_NAME from user_indexes where table_name = tab order by 1 ;
IND1 VARCHAR2(30);
IND2 VARCHAR2(30);
IND3 VARCHAR2(30);
COUNTER NUMBER := 1 ;
pos1 varchar2(5) ;
pos2 varchar2(5) ;
pos3 varchar2(5) ;
BEGIN
FOR C1 IN MY_IND LOOP
IF COUNTER = 1 THEN
begin
select a.column_position
into pos1
from user_ind_columns a
where a.table_name = tab
and a.column_name = col
and a.index_name = c1.IND_name ;
exception
when no_data_found then
  null;
end;
END IF;
IF COUNTER = 2 THEN
begin
select a.column_position
into pos2
from user_ind_columns a
where a.table_name = tab
and a.column_name = col
and a.index_name = c1.IND_name ;
exception
when no_data_found then
  null;
end;
END IF;
IF COUNTER = 3 THEN
begin
select a.column_position
into pos3
from user_ind_columns a
where a.table_name = tab
and a.column_name = col
and a.index_name = c1.IND_name ;
exception
when no_data_found then
  null;
end;
END IF;
COUNTER := COUNTER + 1;
END LOOP ;
if ind_no = 1 then
return pos1 ;
elsif ind_no = 2 then
return pos2 ;
elsif ind_no = 3 then
return pos3 ;
end if;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,70));
RETURN NULL;
end;