Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL Associative Arrays - Index Not In Array

Re: PL/SQL Associative Arrays - Index Not In Array

From: <andrewst_at_onetel.com>
Date: 9 Jun 2005 02:13:24 -0700
Message-ID: <1118308404.022152.155970@g43g2000cwa.googlegroups.com>


absinth 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.

SQL> declare
  2 type tabtype is table of number index by varchar2(10);   3 tab tabtype;
  4 x number;
  5 begin
  6 begin
  7 x := tab('Oracle');
  8 exception

  9      when no_data_found then
 10        x := null;

 11 end;
 12 dbms_output.put_line('x='||x);
 13 end;
 14 /
x=

PL/SQL procedure successfully completed. Received on Thu Jun 09 2005 - 04:13:24 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US