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
On 9 Jun 2005 01:07:24 -0700, "absinth" <absinth_at_gmail.com> wrote:
>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.
declare
type blah_tab is table of varchar2(30)
index by varchar2(10);
blah blah_tab;
begin
blah('hello') := 'I';
blah('Oracle') := NULL;
dbms_output.put_line('Blah(hello): ' || blah('hello') ); dbms_output.put_line('Blah(Oracle): ' || blah('Oracle') );
--Or, if you want to see the text "NULL", then dbms_output.put_line('Blah(Oracle): ' || NVL(blah('Oracle'), 'NULL') );
end;
/
Hope that helps,
Lewis
Author, ItToolBox Blog: An Expert's Guide to Oracle http://blogs.ittoolbox.com/oracle/guide/
Topic Editor, Suite101.com: Oracle Database http://www.suite101.com/welcome.cfm/oracle
Sign up for courses here:
http://www.suite101.com/suiteu/default.cfm/416752
![]() |
![]() |