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

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;

Related

How can I drop and re-create a pluggable database in Oracle DB 18c XE? [duplicate]

I'm trying to execute a script on SQL PLus, it's simple.
SET serveroutput ON;
DECLARE
mode NUMBER(1) := 1;
IF (mode = 1) THEN
prompt 'HERE'
END IF;
prompt 'fim'
I call the script from SQLPlus using sqlplus user/pw#db and #myscript.sql after a successful connection. But the output is strange for me:
Conectado a:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> #myscript.sql
9
10
11
And it continues to print this sequence indefinitely.
What am I doing wrong?
From your edited question... you have to terminate the PL/SQL block with a / on a new line to make it end and run, otherwise SQL*Plus will keep prompting for more lines of code (which is the numbers you're seeing). The documentation shows how to run PL/SQL blocks. And prompt is a SQL*Plus command so you can't use it inside a PL/SQL block. You also don't have your block syntax right:
SET serveroutput ON;
DECLARE
mode NUMBER(1) := 1;
BEGIN
IF mode = 1 THEN
DBMS_OUTPUT.PUT_LINE('HERE');
END IF;
END;
/
prompt fim
You cannot use sqlplus command in plsql.We can use dbms_output instead which will display the output in SQL prompt
SET serveroutput ON;
DECLARE
mode NUMBER(1) := 1;
BEGIN
IF (mode = 1) THEN
dbms_output.put_line('HERE');
END IF;
dbms_output.put_line('fim');
END;
/
Go to your oracle home Oracle\product\<version>\client_2\sqlplus\admin\glogin.sql and add the following lines to enable printing globally,
SET ECHO ON;
SET TERM ON;
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
SET DEFINE OFF;

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 do I select a variables value in SQL Developer

Problem
I just want to see the value of a variable. I don't understand why this has to be so difficult.
My SQL Statement
--set serveroutput on format wrapped; Tried this too
SET SERVEROUTPUT ON;
--DBMS_OUTPUT.ENABLE(32000); Tried with, and without this
vend_num xx.VENDOR_CWT.VEND_NO%TYPE;
SELECT vend_no
INTO vend_num
FROM xx.VENDOR_NAME
WHERE VENDOR_NAME1 = 'xxxx';
dbms_output.put_line(vend_num);
The Error I'm Geting
Error starting at line 13 in command:
dbms_output.put_line(vend_num)
Error report:
Unknown Command
What I've Tried
I've tried the following answers:
Print text in Oracle SQL Developer SQL Worksheet window
Printing the value of a variable in SQL Developer
I've done what this answer suggested with the gui: https://stackoverflow.com/a/7889380/496680
I've tried exec dbms_output[...] as some posts have suggested.
Question
How do I just print the value of vend_num;
DBMS_Output is a PL/SQL package, so you'd call it from within PL/SQL code.
declare
end_num xx.VENDOR_CWT.VEND_NO%TYPE;
begin
SELECT vend_no
INTO vend_num
FROM xx.VENDOR_NAME
WHERE VENDOR_NAME1 = 'xxxx';
dbms_output.put_line(vend_num);
end;
/

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);

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

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.

Resources