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: Bind Variable in Procedure

Re: Bind Variable in Procedure

From: Jim Smith <jim_at_jimsmith.demon.co.uk>
Date: Sun, 10 Jul 2005 12:28:43 +0100
Message-ID: <citjuaGrZQ0CFwyh@jimsmith.demon.co.uk>


In message <42d0a9af$1_2_at_rain.i-cable.com>, lee@?.?.invalid writes
>Hi,
>
>A simple silly question from a beginner - I cannot find related info
>explicitly explained in the textbook.
>
>Is iSQL*PLUS bind variable limited to anonymous block? My personal
>interpretation is that named block could be called by any host environments,
>and we cannot guarantee the availability of host variables in these
>environments, so it is not allowed in named block.
>
>This anonymous block is ok:
>/* in sqlplus issues: variable var1 number
>* /
>DECLARE
>BEGIN
> dbms_output.put_line('value is '|| :var1);
>END;
>
>If I turn it into a function:
>
>CREATE OR REPLACE FUNCTION somefunc RETURN number
>BEGIN
> dbms_output.put_line('value is '|| :var1);
> return 1;
>END;
>
>It produces error complaining :var is invalid.
>
>Thx for answering such a simple question.
>
>

Named blocks use 'normal' variables like any other programming language.

CREATE OR REPLACE FUNCTION somefunc(var1 in number) RETURN number BEGIN
    dbms_output.put_line('value is '|| var1);     return 1;
END; TO call this from sql*sql plus you need to do something like this

variable var1 number
variable result1 number
begin
  :number:=somefunc(:var1);
end;

To call it from another PL/SQL block

declare
 var2 number:=2;
 result1 number;
 begin
   result1:=somefunc(var2);
 end;

(All code untested)

-- 
Jim Smith
Because of their persistent net abuse, I ignore mail from
these domains (among others) .yahoo.com .hotmail.com .kr .cn .tw
For an explanation see <http://www.jimsmith.demon.co.uk/spam>
Received on Sun Jul 10 2005 - 06:28:43 CDT

Original text of this message

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