Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Using TRIM to Decrease the Size of a Collection


DECLARE

TYPE numlist IS TABLE OF NUMBER;

n NUMLIST := Numlist(1,2,3,5,7,11);

PROCEDURE print_numlist

(the_list NUMLIST)

IS

output VARCHAR2(128);

BEGIN

IF n.COUNT = 0 THEN

dbms_output.Put_line('No elements in collection.');

ELSE

FOR i IN the_list.FIRST.. the_list.LAST LOOP

output := output

||Nvl(To_char(The_list(i)),'NULL')

||' ';

END LOOP;



dbms_output.Put_line(output);

END IF;

END;

BEGIN

Print_numlist(n);



n.TRIM(2); -- Remove last 2 elements.



Print_numlist(n);



n.TRIM; -- Remove last element.



Print_numlist(n);



n.TRIM(n.COUNT); -- Remove all remaining elements.



Print_numlist(n);



-- If too many elements are specified,

-- TRIM raises the exception SUBSCRIPT_BEYOND_COUNT.

BEGIN

n := Numlist(1,2,3);



n.TRIM(100);

EXCEPTION

WHEN subscript_beyond_count THEN

dbms_output.Put_line('I guess there weren''t 100 elements that could be
trimmed.'
);

END;



-- When elements are removed by DELETE, placeholders are left behind. TRIM counts

-- these placeholders as it removes elements from the end.

n := Numlist(1,2,3,4);



n.DELETE(3); -- delete element 3



-- At this point, n contains elements (1,2,4).

-- TRIMming the last 2 elements removes the 4 and the placeholder, not 4 and 2.

n.TRIM(2);



Print_numlist(n);

END;

/


Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-