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: Lewis C <lewisc_at_excite.com>
Date: Thu, 09 Jun 2005 08:30:49 GMT
Message-ID: <lgvfa15vphfuu4vg6bnhc8vuudnqingpf4@4ax.com>


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



Lewis R Cunningham

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


Received on Thu Jun 09 2005 - 03:30:49 CDT

Original text of this message

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