How do I Suppress "PL/SQL procedure successfully completed" message in sqlplus? - oracle

Is there a way that you can have SERVEROUTPUT set to ON in sqlplus but somehow repress the message "PL/SQL procedure successfully completed" that is automatically generated upon completed execution of a plsql procedure?

Use the command:
SET FEEDBACK OFF
before running the procedure. And afterwards you can turn it back on again:
SET FEEDBACK ON

This has worked well for me in sqlplus, but I did just notice that "set feedback off" suppresses errors in Sql Developer (at least version 17.2.0.188). Just something to be aware of if you use Sql Developer:
create or replace procedure test_throw_an_error as buzz number; begin dbms_output.put_line('In test_throw_an_error. Now, to infinity!'); buzz:=1/0; end;
/
set serveroutput on
set feedback off
exec test_throw_an_error;
exec dbms_output.put_line('Done, with feedback off');
set feedback on
exec test_throw_an_error;
exec dbms_output.put_line('Done, with feedback on');
Result:
Procedure TEST_THROW_AN_ERROR compiled
In test_throw_an_error. Now, to infinity!
Done, with feedback off
In test_throw_an_error. Now, to infinity!
Error starting at line : 11 in command -
BEGIN test_throw_an_error; END;
Error report -
ORA-01476: divisor is equal to zero
ORA-06512: at "ECTRUNK.TEST_THROW_AN_ERROR", line 1
ORA-06512: at line 1
01476. 00000 - "divisor is equal to zero"
*Cause:
*Action:
Done, with feedback on
PL/SQL procedure successfully completed.

Related

pl /sql set ORA-00922: missing or invalid option on set serveroutput on;

set serveroutput on;
DECLARE
message varchar2(20):= 'Hello, World!';
BEGIN dbms_output.put_line(message);
END;
/
As others have indicated "set server output on" is a SQL*Plus command. If you need that functionality in plsql the you're looking for is DBMS_OUTPUT.ENABLE. Your above block becomes:
declare
message varchar2(20) := 'Hello World';
begin
dbms_output.enable;
dbms_output.put_line(message);
end ;
If use SQL*plus then this code works fine.
[oracle#krw-sql-ora12-01 ~]$ sqlplus scott/tiger
SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 22 08:07:25 2019
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set serveroutput on;
SQL> DECLARE
2 message varchar2(20):= 'Hello, World!';
3 BEGIN dbms_output.put_line(message);
4 END;
5 /
Hello, World!
PL/SQL procedure successfully completed.
SQL>
It seems that you used SET SERVEROUTPUT ON within the PL/SQL procedure (or an anonymous block), e.g.
SQL> begin
2 set serveroutput on;
3 end;
4 /
set serveroutput on;
*
ERROR at line 2:
ORA-06550: line 2, column 7:
PL/SQL: ORA-00922: missing or invalid option
ORA-06550: line 2, column 3:
PL/SQL: SQL Statement ignored
SQL>
Perhaps you didn't post everything you really have; is that SET command part of a larger procedure? If so, move it out.
You mention that you are using toad. You have to use the lightning bolt instead of the green triangle. Hover your mouse over the two icons. You will see the green triangle says: Execute/compile statement at caret. You will see the lightning bolt says: Execute as script.
set serveroutput on;
DECLARE
message varchar2(20):= 'Hello, World!';
BEGIN dbms_output.put_line(message);
END;
/

sqlcl vs sqlplus pl/sql compatability

I apologize up-front for this super-lightweight question, but I'm missing something when starting to work with sqlcl as a potential replacement for sqlplus.
sqlcl is compelling, but I'm troubled in that I'm missing how to run anonymous-blocks interactively. The below example works fine when saved as Little-Anonymous-Block.sql and run in sqlcl via #Little-Anonymous-Block.sql, but the raw pl/sql fails with the the below PLS-00103.
Little-Anonymous-Block.sql:
BEGIN
DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
END;
/
Running as a Script:
SQL> SET SERVEROUTPUT ON;
SQL> #Little-Anonymous-Block.sql;
This anonymous-block ran in sqlcl!
PL/SQL procedure successfully completed.
But running ad-hoc:
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
3 END;
4 /
gives:
Error starting at line : 1 in command -
BEGIN
DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
END;/
PLS-00103: Encountered the symbol "/" The symbol "/" was ignored.
sqlcl appears to be conjoining the "/" with the block-terminating END;
The same command works fine in sqlplus.
Can you tell me, how do I interactively run anonymous blocks in sqlcl? I've got the early-adopter release from 20160513. java 8.0_77. Apologies for this question if its in the sqlcl manual, I didn't find much to go by on the oracle sqlcl-page.
I've found that you can run an anonymous block with exec but that has its limitations (e.g. all code on one line).
As far as I can tell what you've found is a bug. A workaround would be to end your block with a . then execute the buffer with a / as shown below:
This was indeed a bug. It should be fixed in the latest release on OTN
BARRY#orcl☘ >BEGIN
2 DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
3 END;
4 /
PL/SQL procedure successfully completed.
BARRY#orcl☘ >l
1 BEGIN
2 DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
3* END;
BARRY#orcl☘ >

How to make to see the output result to execute PL/SQL from SQL Plus?

When i run PL/SQL statment from SQL Plus,I don't see my output result.However,it was successful completed but it don't show output result.
My code is here
DECLARE
message varchar2(20):= 'Hello World';
BEGIN
dbms_output.put_line(message);
END;
/
RESULT: PL/SQL is successfully completed.
It didn't show Hello World output.
You need use the command set serveroutput on to configure buffering for dbms_output like below. Check this Oracle Community Post
set serveroutput on size 15000;

how to handle sql script from unix

I am actually calling an SQL script from Unix using the below code. The SQL script has millions of DML's which will be run on my database. The requirement is that if an DML fails then the script should abort with an exit code rather than skipping to the next DML. Currently,it is executing all the DML's without breaking at the DML that failed. We actually need more control on the script. How can we achieve this? Plz help.
SCRIPT BODY
#! /bin/sh
echo "Script started at `date`"
#************** Execute the extract sql on Staging database***************#
`sqlplus -s $CCBSTGID/$CCBSTGPASSWRD#$CCBSTGDBASE <<EOF
whenever sqlerror exit 2;
whenever error exit 3;
set termout on
set echo on
set serveroutput on
set pagesize 0
set linesize 500
set heading off
set verify on
set feedback on
spool output1.txt;
#DMLFile.sql
spool off;
quit;
EOF`
RC=$?
echo $RC
if [ ${RC} != 0 ]
then
echo "Script execution failed"
exit 1
fi
The problem is that you aren't wrapping the DML statements within PL/SQL blocks so the WHENEVER SQLERROR ... isn't working like you expect. Here is a test case demonstrating the issue.
-- File: dmlfile.sql
update a set name = 'A';
foo; -- erroneous command to cause error
update a set name = 'B';
Before...
C:\>perl wrapper.pl
1 row updated.
SP2-0042: unknown command "foo" - rest of line ignored.
1 row updated.
Oops, both updates statements executed; script did not exit after error.
After wrapping with BEGIN and END
-- File: dmlfile.sql
begin
update a set name = 'A';
foo; -- erroneous command to cause error
update a set name = 'B';
end;
/
Running it:
C:\>perl wrapper.pl
foo; -- erroneous command to cause error
*
ERROR at line 3:
ORA-06550: line 3, column 2:
PLS-00201: identifier 'FOO' must be declared
ORA-06550: line 3, column 2:
PL/SQL: Statement ignored
Also, I don't know of any command WHENEVER ERROR, perhaps you were thinking WHENEVER OSERROR ?
See previous answer: PL/SQL: is there an instruction to completely stop the script execution?
Try wrapping all of your DML in a BEGIN ... END block:
-- DMLFile.sql
BEGIN
-- your DML statements here
END;
/
or wrap each individual logical block of statements in a block.
-- DMLFile.sql
WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;
BEGIN
-- block 1
END;
/
BEGIN
-- block 2
END;
/
WHENEVER SQLERROR EXIT is a SQLPlus directive, not standard SQL, but is fairly portable; it works in SQLPlus, SQL Developer, Toad, PL/SQL Developer, SQLsmith and others.
An alternative would be to use some other GUI client around your DML or pass the whole script to a tool that can do batch mode. Toad will stop after one error and prompt you.
SQLPLUS couldn't parse the command so it never made it to SQL. The SP2-0042 error is a sqlplus error, so it doesn't get caught by the WHENEVER SQLERROR EXIT directive. Sadly, There's no equivalent SQLPLUSERROR directive....
However, starting in the 11g sqlplus (not the database), Oracle has provided a error logging facility that can be used to trap various errors.
SQLPLUS> set errorlogging on
I finally found the reference here: SQLPlus User Guide

PL SQL output is not getting displayed

I have fairly simply code ..running in Oracle Virtualbox. However for some reason it is not displaying pl/sql output.
Here is code snippet
SQL> set serveroutput on
SQL> list
1 Create or Replace procedure mytz
2 IS
3 v_mytz TIMESTAMP WITH TIME ZONE DEFAULT '2013-05-05 12:00:00 AM';
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE ('Default timestamp is ' );
6* end mytz ;
SQL> /
Procedure created.
SQL>
Is there anything I need to do special to see the output on SQL prompt ?
You have to actually run the procedure, not just create it, e.g.:
set serverputput on
exec mytz;
The set serveroutput SQL*Plus command has to be in the session the procedure is executed, not the one where it is created (if they are different).
You are not showing the value of your variable at the moment; maybe you wanted this?
dbms_output.put_line('Default timestamp is: ' || v_mytz);

Resources