HOWTO USE PLSQL INDEX_BY TABLE IN SHORT

PLSQL Collections are not as much used as Java Collections. Below a short example of some of the futures of Index-by Table collection type.


DECLARE
TYPE NTBLTYPE IS TABLE OF VARCHAR2(100) INDEX BY INTEGER;
X INTEGER;
V1 NTBLTYPE;
BEGIN
V1(1) := 'value1';
V1(100) := 'value100';

IF V1.EXISTS(1) THEN
dbms_output.put_line('V1(1) exists');
END IF;
dbms_output.put_line('V1.COUNT: ' || V1.COUNT); -- 2
dbms_output.put_line('V1.FIRST: ' || V1.FIRST); -- 1
dbms_output.put_line('V1.LAST: ' || V1.LAST); -- 100
-- ALSO PRIOR AND NEXT AND DELETE METHODS

-- INDEX BY TABLE HAS NO "LIMIT" METHOD BECAUSE IT IS UNBOUNDED

--LOOPING
X:=1
LOOP
dbms_output.put_line(V1(X));
X:=V1.NEXT(X);
EXIT WHEN X IS NULL;
END LOOP;
END;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s