Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL Associative Arrays - Index Not In Array
"absinth" <absinth_at_gmail.com> wrote in message
news:1118304444.300506.264620_at_g44g2000cwa.googlegroups.com...
| Say I have an associative array 'blah' and it has members 'hello' and
| 'bye.'
|
| How can I instruct Oracle to return a NULL if I lookup the array and
| the value isn't found?
|
| E.g.
| blah('hello') might map to '1'
| But I want blah('Oracle') to return NULL.
I'm still new to PL/SQL, but this would be my attempt:
MyMap MyMapType;
Value VARCHAR2( 15 );
BEGIN IF Key IS NULL THEN
RETURN 'Error: Source string is NULL'; END IF;
Value:= MyMap( Key );
RETURN Value;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN NULL;
END;
/
Hope this help's.
Cheers,
Chris Val
PS: I would love to hear from the experts of ways
that I can improve my PL/SQL code so that I can write better code in PL/SQL - I'm coming from C++. Received on Thu Jun 09 2005 - 06:19:26 CDT