Home » SQL & PL/SQL » SQL & PL/SQL » Taking Input from console and Displaying Message using DBMS_OUTPUT.PUT_LINE
icon5.gif  Taking Input from console and Displaying Message using DBMS_OUTPUT.PUT_LINE [message #225130] Sun, 18 March 2007 04:08 Go to next message
praveenprajapati
Messages: 1
Registered: March 2007
Junior Member
Hello freinds,
I have a query,
consider the sample pl/sql block
declare
v_choiceno number(3);
V1 number(3);
v2 number(3);
begin
v_choiceno:=0;

while v_choiceno <> 3
loop
DBMS_OUTPUT.PUT_LINE('****************');
DBMS_OUTPUT.PUT_LINE(' 1. ADD *');
DBMS_OUTPUT.PUT_LINE(' 2. SUB *');
DBMS_OUTPUT.PUT_LINE(' 3. EXIT *');
DBMS_OUTPUT.PUT_LINE('****************');
DBMS_OUTPUT.PUT_LINE('ENTER YOUR CHOICE NO:');
v_choiceno:=&v_choiceno;

v1:=&v1;
v2:=&v2;
case v_choiceno
loop
when 1 then
DBMS_OUTPUT.PUT_LINE('ADD '||v1||' + '||v2||'='||v1+v2);
exit;

when 2 then
DBMS_OUTPUT.PUT_LINE('SUB '||v1||' - '||v2||'='||v1-v2);
exit;

when 3 then
EXIT;

end loop;
end loop;
end;

/* Now my query is why does this messages are not displayed
first .Here when I execute the above code user input is given higher priority and there after only messages are printed on console.
Re: Taking Input from console and Displaying Message using DBMS_OUTPUT.PUT_LINE [message #225137 is a reply to message #225130] Sun, 18 March 2007 05:49 Go to previous message
rleishman
Messages: 3724
Registered: October 2005
Location: Melbourne, Australia
Senior Member
The & replacement variables are a SQL*Plus construct, not PL/SQL. SQL*Plus first parses the entire block, prompts to replace & variables, and sends the entire block off to the PL/SQL engine to be executed. The PL/SQL runs to completion, buffering any output, then returns control to SQL*Plus, which displays all of the buffered messages at once.

Ross Leishman
Previous Topic: Removing the first occurance of a number in a string
Next Topic: procedure & function
Goto Forum:
  


Current Time: Sun Dec 04 06:13:51 CST 2016

Total time taken to generate the page: 0.07962 seconds