Home > front end >  oracle not accepting output from the user and throwing error
oracle not accepting output from the user and throwing error

Time:10-03

Hi i was trying to create a simple sum function which takes input from the user and displays the output but whenever i run the code it is throwing the errors which i absolutely don't know what they are. can anyone please help regarding this matter.

the code for the program is:

set serveroutput on
declare
a number;
b number;
s number;
begin
a:= &a;
b:= &b;
s:=a b;
dbms_output.put_line('sum: '||s);
end;
/

the error encountered are:

Error at line 1/5: ORA-00922: missing or invalid option
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_220100", line 847
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_220100", line 833
ORA-06512: at "APEX_220100.WWV_FLOW_DYNAMIC_EXEC", line 1903


1. set serveroutput on
2. declare
3. a number;

CodePudding user response:

You're missing a semi-colon on the very first line:

set serveroutput on;

CodePudding user response:

That's Apex' "SQL Command", and you can't use substitution variables there.

As you said:

i was trying to create a simple sum function

then do so - create a function (write create function and press Ctrl Enter to actually create it; then call it using the select statement by selecting it (mark the whole line with a mouse) and execute it the same way. See the result at the bottom of the screenshot):

enter image description here


On the other hand, if it were SQL*Plus, then your code would work:

SQL> set ver off
SQL> set serveroutput on
SQL> declare
  2  a number;
  3  b number;
  4  s number;
  5  begin
  6  a:= &a;
  7  b:= &b;
  8  s:=a b;
  9  dbms_output.put_line('sum: '||s);
 10  end;
 11  /
Enter value for a: 1
Enter value for b: 3
sum: 4

PL/SQL procedure successfully completed.

SQL>
  • Related