Friday 25 July 2008

Quick tip 3: How to get List index in oracle forms builder

As i can see, many people have this problem. They have a hard time to get index of an item selected in some list.
As I can tell, there isn’t a function like GET_LIST_INDEX() or something like that.
I had this problem myself few times before, and then I wrote this PL/SQL function:

FUNCTION getListIndex (LIST IN VARCHAR2, VAL IN VARCHAR2) RETURN INTEGER IS
BEGIN
IF To_Number(Get_List_Element_Count(LIST))>0 THEN
FOR i IN 1..To_Number(Get_List_Element_Count(LIST)) LOOP
IF Get_List_Element_Value(LIST,i) = VAL THEN
Return i;
END IF;
END LOOP;
ELSE
RETURN -1;
END IF;
END;


And to find out which index you selected by clicking on the list, call
getListIndex(‘blockX.listX , :blockX.listX);
This will return selected index, and -1 if the list is empty…
For example, to delete something from some list you just cdouble-clicked, call:

-- on WHEN-MOUSE-DOUBLECLICK trigger:
...
DELETE_LIST_ELEMENT('block3.list4',getListIndex('block3.list4',:block3.list4));
...

2 comments:

Anonymous said...

MUCHAS GRACIAS POR EL APORTE ME HA AYUDADO MUCHO :-), DE VERDAD MUCHAS GRACIAS

Anonymous said...

Nice function, I have used it.
Thank you.