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.

Collection Exceptions


DECLARE

TYPE WORDLIST IS TABLE OF VARCHAR2(5);

WORDS WORDLIST;

ERR_MSG VARCHAR2(100);

PROCEDURE DISPLAY_ERROR

IS

BEGIN

ERR_MSG := SUBSTR(SQLERRM,1,100);



DBMS_OUTPUT.PUT_LINE('Error message = '

||ERR_MSG);

END;

BEGIN

BEGIN

WORDS(1) := 10; -- Raises COLLECTION_IS_NULL



-- A constructor has not been used yet.

-- Note: This exception applies to varrays and nested tables,

-- but not to associative arrays which do not need a constructor.

EXCEPTION

WHEN OTHERS THEN

DISPLAY_ERROR;

END;



-- After using a constructor, we can assign values to the elements.

WORDS := WORDLIST('1st','2nd','3rd'); -- 3 elements created



-- Any expression that returns a VARCHAR2(5) is valid.

WORDS(3) := WORDS(1)

||'+2';



BEGIN

WORDS(3) := 'longer than 5 characters'; -- Raises VALUE_ERROR



-- The assigned value is too long.

EXCEPTION

WHEN OTHERS THEN

DISPLAY_ERROR;

END;



BEGIN

WORDS('B') := 'dunno'; -- Raises VALUE_ERROR



-- The subscript (B) of a nested table must be an integer.

-- Note: Also, NULL is not allowed as a subscript.

EXCEPTION

WHEN OTHERS THEN

DISPLAY_ERROR;

END;



BEGIN

WORDS(0) := 'zero'; -- Raises SUBSCRIPT_OUTSIDE_LIMIT



-- Subscript 0 is outside the allowed subscript range.

EXCEPTION

WHEN OTHERS THEN

DISPLAY_ERROR;

END;



BEGIN

WORDS(4) := 'maybe'; -- Raises SUBSCRIPT_BEYOND_COUNT



-- The subscript (4) exceeds the number of elements in the table.

-- To add new elements, call the EXTEND method first.

EXCEPTION

WHEN OTHERS THEN

DISPLAY_ERROR;

END;



BEGIN

WORDS.DELETE(1);



IF WORDS(1) = 'First' THEN

NULL;

END IF; -- Raises NO_DATA_FOUND



-- The element with subcript (1) has been deleted.

EXCEPTION

WHEN OTHERS THEN

DISPLAY_ERROR;

END;

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 :-