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: ACCEPT in SQL*Plus

Re: ACCEPT in SQL*Plus

From: andrewst <member14183_at_dbforums.com>
Date: Tue, 08 Apr 2003 14:52:47 +0000
Message-ID: <2742488.1049813567@dbforums.com>

Originally posted by Francesco Sblendorio
> >> variable abc number;
> >> accept abc;
> >> begin
> >> dbms_output.put_line( :abc );
> >> end;
> >> /
>
> Thanks for your help.
> I tried the script you posted: it's executed without errors, but
> it doesn't
> print nothing out, although I already launched "set serveroutput on".
>
> What's the difference between a "variable" and a "host variable"?
>

The code above is incorrect, because the ACCEPT command gets a value into a substitution variable called &abc, which has no connection with a variable called abc. It would have to be:

accept abc

begin
  dbms_output.put_line(&abc);
end;
/

Substitution variables are processed by SQL Plus, e.g. if &abc is set to 123 then above code is processed as:

begin
  dbms_output.put_line(123);
end;

The value 123 is a literal as far as PL/SQL is concerned.

Variables created with the VARIABLE command are true variables, which can be referenced within PL/SQL like :abc. The value can be changed within PL/SQL, e.g.

variable abc number

begin
  :abc := 123;
  dbms_output.put_line(:abc);
end;
/

--
Posted via http://dbforums.com
Received on Tue Apr 08 2003 - 09:52:47 CDT

Original text of this message

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