Set Serveroutput On throught PL/Sql
Hi All,
In order to display output through DBMS_output.put_line one need to do set serveroutput on, I want to do that through PL/SQL as application I work on user forget to do so. I want to come over that. Although its useful sometimes as application supports both ways even if for some condition I don't want to display output and same code can be used for displaying output.Any suggestions
thanks
How is the application executing the pl/sql with the dbms_out statement in it?
Either the sqlplus script that contains the code should have a set serveroutput on size nnnn right before the pl/sql code is executed OR
the application should read the dbms_output buffer using the dbms_output.get_line procedure and use its own functionality to display the output. In this case you enable the buffer using dbms_output.enable and when done dbms_output.disable. We have done this in pro*c programs.
HTH -- Mark D Powell --
Similar Messages
-
Error using SET SERVEROUTPUT ON command
HI,
I am using Hudson configuration tool for automated deployment.The script was running successfully without spool command,but when i use these commands i got below exception.
spool file1_select.log
SET SERVEROUTPUT ON;
DECLARE
l_vc_user VARCHAR2 (50);
BEGIN
SELECT USER INTO l_vc_user FROM DUAL;
DBMS_OUTPUT.put_line ('CURRENT USER IS : ' || l_vc_user);
SELECT global_name INTO l_vc_user FROM global_name;
DBMS_OUTPUT.put_line ('CURRENT DB IS : ' || l_vc_user);
END;
select systimestamp from dual;
select systimestamp from dual;
spool off;
we are getting the exception when executing using the java plugin.
“ERROR] Failed to execute: /* Formatted on 4/18/2012 4:36:12 PM (QP5 v5.126) */ spool file1_select.log SET SERVEROUTPUT ON
[ERROR] java.sql.SQLException: ORA-00900: invalid SQL statement
How to proceed the scripts with these commands in java plugin .Is there any other way to resolve it. Please do the needful.
Edited by: 927851 on Apr 19, 2012 3:34 AM
Edited by: 927851 on Apr 19, 2012 4:15 AMTry to put serveroutput statement before spool statement.
Hope it helps you,
Fabrizio -
Using SET SERVEROUTPUT ON in procedure
Hi,
Can I use SET SERVEROUTPUT ON inside a procedure. The reason is I am building a procedure in Toad and will execute in SqlPlus. In future I will only use SqlPlus to execute and view my result.No.
Although you can use DBMS_OUTPUT.ENABLE, it only re-enables output that was previously disabled (with DBMS_OUTPUT.DISABLE). It does not alter the current SQL*Plus SERVOUTPUT setting.
For example,
SQL> set serveroutput on size 1000000
SQL>
SQL> begin
2 dbms_output.enable(1000000);
3 dbms_output.put_line('Eat more bananas');
4 end;
5 /
Eat more bananas
PL/SQL procedure successfully completed.
SQL> set serveroutput off
SQL>
SQL> r
1 begin
2 dbms_output.enable(1000000);
3 dbms_output.put_line('Eat more bananas');
4* end;
PL/SQL procedure successfully completed.
SQL> show serverout
serveroutput OFF -
SQL Developer 1.5.3: SIZE honored in SET SERVEROUTPUT ON SIZE nbr ?
I'm running some PL/SQL in SQL Developer 1.5.3 and am getting some buffer overflow error messages while using dbms_output.put_line.
At the top of my script, I've put:
set serveroutput on size 100000
But get these errors:
ORA-20000: ORU-10027: buffer overflow, limit of 20000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 198
ORA-06512: at "SYS.DBMS_OUTPUT", line 139
ORA-06512: at line 28
Does SQL Developer 1.5.3 not, in fact, honor the SIZE portion of SET SERVEROUTPUT ON? If not, can this be set in the preferences? (couldn't find it).
Thanks.
DanaDana N wrote:
Note... I'm running Oracle 9i, soon to be 10g. Don't know if that matters. Seems in 11g, there's another way to set the buffer size specifically for dbms_output, e.g. dbms_output.enable(100000)-- or null for unlimited. I couldn't get this to work on 9i.
Danadbms_output.enable(buffer_size) has been available since 9i if not before. -
Hi
I'm trying to print an XML document into a PL/SQL region.
Here's the region source:
declare
queryCtx DBMS_XMLquery.ctxType;
result CLOB;
begin
queryCtx := DBMS_XMLQuery.newContext('select * from mytable');
result := DBMS_XMLQuery.getXML(queryCtx);
printClobOut(result);
DBMS_XMLQuery.closeContext(queryCtx);
end;
And here's the 'printClobOut' procedure:
PROCEDURE printClobOut(result IN OUT NOCOPY CLOB) is
xmlstr varchar2(32767);
line varchar2(2000);
set serveroutput on
begin
xmlstr := dbms_lob.SUBSTR(result,32767);
loop
exit when xmlstr is null;
line := substr(xmlstr,1,instr(xmlstr,chr(10))-1);
dbms_output.put_line('| '||line);
xmlstr := substr(xmlstr,instr(xmlstr,chr(10))+1);
end loop;
end printClobOut
For some reason it doesn't like the 'set serveroutput' command, and gives me this error:
ERROR at line 4: PLS-00103: Encountered the symbol "ON" when expecting one of the following: := . ( @ % ; not null range default character The symbol "; was inserted before "ON" to continue.
If I don't have that command in there, it doesn't print anything out.
Any ideas?
Cheers
-DaveDavid,
That statement is not part of the PL/SQL language. It's used only in SQL*Plus to enable output when using dbms_output. You need to use htp.p with the web components instead of dbms_output, and htf.escape_sc within that if necessary to escape special characters, if any, e.g., htp.p(substr(xmlstr,1,instr(xmlstr,chr(10))-1)) or htp.p(htf.escape_sc(substr(xmlstr,1,instr(xmlstr,chr(10))-1))).
Scott -
A question about the impact of SQL*PLUS SERVEROUTPUT option on v$sql
Hello everybody,
SQL> SELECT * FROM v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL>
OS : Fedora Core 17 (X86_64) Kernel 3.6.6-1.fc17.x86_64I would like to ask a question about the SQL*Plus SET SERVEROUTPUT ON/OFF option and its impact on queries on views such as v$sql and v$session. Here is the problem
Actually I define three variables in SQL*Plus in order to store sid, serial# and prev_sql_id columns from v$session in order to be able to use them later, several times in different other queries, while I'm still working in the current session.
So, here is how I proceed
SET SERVEROUTPUT ON; -- I often activate this option as the first line of almost all of my SQL-PL/SQL script files
SET SQLBLANKLINES ON;
VARIABLE mysid NUMBER
VARIABLE myserial# NUMBER;
VARIABLE saved_sql_id VARCHAR2(13);
-- So first I store sid and serial# for the current session
BEGIN
SELECT sid, serial# INTO :mysid, :myserial#
FROM v$session
WHERE audsid = SYS_CONTEXT('UserEnv', 'SessionId');
END;
PL/SQL procedure successfully completed.
-- Just check to see the result
SQL> SELECT :mysid, :myserial# FROM DUAL;
:MYSID :MYSERIAL#
129 1067
SQL> Now, let's say that I want to run the following query as the last SQL statement run within my current session
SELECT * FROM employees WHERE salary >= 2800 AND ROWNUM <= 10;According to Oracle® Database Reference 11g Release 2 (11.2) description for v$session
http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_3016.htm#REFRN30223]
the column prev_sql_id includes the sql_id of the last sql statement executed for the given sid and serial# which in the case of my example, it will be the above mentioned SELECT query on the employees table. As a result, right after the SELECT statement on the employees table I run the following
BEGIN
SELECT prev_sql_id INTO :saved_sql_id
FROM v$session
WHERE sid = :mysid AND serial# = :myserial#;
END;
PL/SQL procedure successfully completed.
SQL> SELECT :saved_sql_id FROM DUAL;
:SAVED_SQL_ID
9babjv8yq8ru3
SQL> Having the value of sql_id, I'm supposed to find all information about cursor(s) for my SELECT statement and also its sql_text value in v$sql. Yet here is what I get when I query v$sql upon the stored sql_id
SELECT child_number, sql_id, sql_text
FROM v$sql
WHERE sql_id = :saved_sql_id;
CHILD_NUMBER SQL_ID SQL_TEXT
0 9babjv8yq8ru3 BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;Therefore instead of
SELECT * FROM employees WHERE salary >= 2800 AND ROWNUM <= 10;for the value of sql_text I get the following value
BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES);Which is not of course what I was expecting to find in v$sql for the given sql_id.
After a bit googling I found the following thread on the OTN forum where it had been suggested (well I think maybe not exactly for the same problem) to turn off SERVEROUTPUT.
Problem with dbms_xplan.display_cursor
This was precisely what I did
SET SERVEROUTPUT OFFafter that I repeated the whole procedure and this time everything worked pretty well as expected. I checked SQL*Plus documentation for SERVEROUTPUT
and also v$session page, yet I didn't find anything indicating that SERVEROUTPUT should be switched off whenever views such as v$sql, v$session
are queired. I don't really understand the link in terms of impact that one can have on the other or better to say rather, why there is an impact
Could anyone kindly make some clarification?
thanks in advance,
Regards,
Dariyoosh>
and also v$session page, yet I didn't find anything indicating that SERVEROUTPUT should be switched off whenever views such as v$sql, v$session
are queired. I don't really understand the link in terms of impact that one can have on the other or better to say rather, why there is an impact
Hi Dariyoosh,
SET SERVEROUTPUT ON has the effect of executing dbms_output.get_lines after each and every statement. Not only related to system view.
Here below what Tom Kyte is explaining in this page:
Now, sqlplus sees this functionality and says "hey, would not it be nice for me to dump this buffer to screen for the user?". So, they added the SQLPlus command "set serveroutput on" which does two things
1) it tells SQLPLUS you would like it <b>to execute dbms_output.get_lines after each and every statement</b>. You would like it to do this network rounding after each call. You would like this extra overhead to take place (think of an install script with hundreds/thousands of statements to be executed -- perhaps, just perhaps you don't want this extra call after every call)
2) SQLPLUS automatically calls the dbms_output API "enable" to turn on the buffering that happens in the package.Regards.
Al -
SET NULL not working in SQL*Plus
DB Version: 10.2.0.4
Question1.
Won't SET NULL work with PL/SQL block?
Question2.
Why is <<>> appearing in several lines (one character per line) as shown below? Sorry about the "jive-quote" thing below, got that after i added code tags.
SQL > show lines
linesize 80
SQL > show pages
pagesize 14
SQL > set null <<>>
SQL > select null from dual;
N
<
<
>
>
SQL > set serveroutput on
SQL > declare
2 v_Val VARCHAR2(100) :='COCOJUMBO';
3 BEGIN
4 SELECT null INTO v_val from dual ;
5 DBMS_output.put_line(v_val);
6 EXCEPTION
7 WHEN NO_DATA_FOUND THEN
8 dbms_output.put_line('Exception:'||SQLERRM);
9 END;
10 /
PL/SQL procedure successfully completed.
SQL >user872043 wrote:
DB Version: 10.2.0.4
Question1.
Won't SET NULL work with PL/SQL block?No. SET NULL is a SQL*Plus command, not a PL/SQL command.
Question2.
Why is <<>> appearing in several lines (one character per line) as shown below? Sorry about the "jive-quote" thing below, got that after i added code tags.That's due to default formatting. For example:
SQL> SET NULL <<>>
SQL> SELECT NULL FROM DUAL;
N
<
<
>
>
SQL> COLUMN col FORMAT A4
SQL> SELECT NULL col FROM DUAL;
COL
<<>> -
I have 10.2.0.1.0 on Windows XP and have set serveroutput on on sqlplus. However, I don't see the out put from dbms_output.put_line('xxxxxx'); the dbms_output.put_line() is not in IF or ELSE condition.
Can anyone please shed a light? Thanks in advance.Dear 782150,
Here is a little illustration for you;
$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Tue Jul 20 17:25:56 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set serveroutput on;
SQL> exec dbms_output.put_line('ogan');
ogan
PL/SQL procedure successfully completed.
SQL> set serveroutput off;
SQL> exec dbms_output.put_line('ogan');
PL/SQL procedure successfully completed.
*SQL> exec dbms_output.enable();*
PL/SQL procedure successfully completed.
*SQL> exec dbms_output.put_line('ogan');*
PL/SQL procedure successfully completed.
*SQL> set serveroutput on;*
SQL> exec dbms_output.put_line('ogan');
*ogan*
*ogan*
PL/SQL procedure successfully completed.
SQL> exec dbms_output.put_line('ogan');
ogan
PL/SQL procedure successfully completed.So it shows two ogan outputs after the dbms_output.enable(). Basically the set serveroutput on should help you but if you can show the SQL you have used it would be better for us to understand the problem.
Hope That Helps,
Ogan -
Execute immediate 'alter session set current_schema = ' failed in PL/SQL
Hi
I am trying to run
EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA = TEST ' ;
in a pl/sql block but it is failing.Can anyone update me on this.
CREATE OR REPLACE PROCEDURE test3
IS
A_COUNT NUMBER(15);
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA = TEST ' ;
SELECT COUNT(*) INTO A_COUNT FROM (
select id from solutions );
END;
/The user who owns the procedure needs to be granted direct select rights on table test.solutions (not via a role). Still will not help. Look what OP is trying to do. In a stored procedure owned by some user (other than TEST) OP is trying to reference user TEST owned table solution without prefixing it with owner. Something like:
SQL> create table u1.test_tbl(x number);
Table created.
SQL> select * from test_tbl;
select * from test_tbl
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> alter session set current_schema = U1;
Session altered.
SQL> select * from test_tbl;
no rows selected
SQL> However, OP tries to do it in a SP using dynamic SQL to change current schema to test. Such change will occur when SP will be executed, not when is it compiled. At compile time we are still under SP owner's schema and therefore select from solutions implies table solutions owned by SP owner, not by TEST. The only way to make SP compile and work OK is to select from solutions also dynamically:
SQL> select sys_context('userenv','current_schema') from dual
2 /
SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
SCOTT
SQL> CREATE OR REPLACE PROCEDURE test3
2 IS
3 A_COUNT NUMBER(15);
4 BEGIN
5 EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA = U1' ;
6 SELECT COUNT(*) INTO A_COUNT FROM (
7 select x from test_tbl );
8 END;
9 /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE TEST3:
LINE/COL ERROR
6/1 PL/SQL: SQL Statement ignored
7/15 PL/SQL: ORA-00942: table or view does not exist
SQL> set serveroutput on
SQL> CREATE OR REPLACE PROCEDURE test3
2 IS
3 A_COUNT NUMBER(15);
4 c sys_refcursor;
5 BEGIN
6 EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA = U1' ;
7 OPEN C FOR 'SELECT COUNT(*) FROM (select x from test_tbl )';
8 FETCH c INTO A_COUNT;
9 dbms_output.put_line(a_count);
10 CLOSE c;
11 END;
12 /
Procedure created.
SQL> insert into u1.test_tbl select rownum from emp;
14 rows created.
SQL> exec test3
14
PL/SQL procedure successfully completed.
SQL> Obviously, as you noted SP owner must have directly granted select on test3.solutions.
SY. -
Command Skipped: SET SERVEROUTPUT ON SIZE 1,000,000
SET SERVEROUTPUT ON SIZE 1,000,000;
declare
v_jan number;
v_feb number;
I put this at the top of my sql block in sql developer and when I run it I get the following...
line 1: SQLPLUS Command Skipped: SET SERVEROUTPUT ON SIZE 1,000,000;
Error starting at line 2 in command:
declare.... [ rest of code block here] ... then...
Error report:
ORA-20000: ORU-10027: buffer overflow, limit of 20000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 32
ORA-06512: at "SYS.DBMS_OUTPUT", line 97
ORA-06512: at "SYS.DBMS_OUTPUT", line 112
ORA-06512: at line 13The DBMS_OUTPUT tab is one of the tabs you'll see when opening a SQL Worksheet. If you take a look at the "Useful Features of SQL Developer" demo under the "Podcasts and Viewlets" link, you'll see the set of tabs below the SQL Worksheet. They include the Results and Script output tabs and the DBMS_OUTPUT tab.
<p>Sue -
Is there any alternative to set serveroutput on
without having to use the set serveroutput on can i make the results display using dbms_output.put_line.i have tried using dbms_output.enable on somebody's advise.
begin
dbms_output.enable;
dbms_output.put_line('xyz');
end;
but the above one is not displaying the result if i don't use set severoutput on. is it must to use set serverout on.is there any alternative keyword or somthing which i can embed in pl/sql block itself to display the result.
thank you.pl/sql is not a user interface tool. It cannot display anything. There are various ways to get to see output from it but whatever method must involve some other facility which has the ability to display stuff.
-
DBMS_OUTPUT & set serveroutput on
Hello:
In my APEX app I am executing a procedure. Within this procedure I have DBMS_OUTPUT.PUT_LINE displaying results after each function.
In order to see the output which is produced by DBMS_OUTPUT, I have to type, set serveroutput on. When I run my procedure in SQL Developer, I see all the results.
When I run my APEX app with this procedure, I am not able to see the results of the DBMS_OUTPUT. It is important that the user see the results after they submit the parameter for the procedure.
Is there a way that I can display the results of DBMS_OUTPUT after my user clicks the SUBMIT button?
Thanks in advance.Hi,
the following example copies the DBMS_OUTPUT messages into a table MESSAGE; instead of this
you can also use an APEX collection or wwv_flow.debug or some other thing ...
declare
v_lines dbms_Output.chararr;
v_numlines pls_integer := 100;
begin
dbms_output.enable; -- activate - equivalent to "set serveroutput on"
dd.change_patient.add_patient_new(:P2_ORG_NUM);
-- get the messages
dbms_output.get_lines(v_lines, v_numlines);
-- insert the messages into a table
for i in 1..v_numlines loop
insert into MESSAGE values (v_lines(i));
end loop;
end;
Edited by: carstenczarski on 25.11.2008 16:07
Edited by: carstenczarski on 25.11.2008 16:08 -
Set "serveroutput on" for the current session.
I'm still new to PL/SQL and I use "*SET SERVEROUTPUT ON SIZE 100000"* always before I run a PL program block to get dbms_output. I really need to know why should we specify a size in this line & what that size will be applied for. Also I need to know whether there is any possibility to set serveroutput enabled for the current session, rather than running this code line before each and every PL block.
I Tried *"ALTER SESSION SET SERVEROUTPUT ON SIZE 1000000"* ; But it was not successfully executed.
Thanks!michaels2 wrote:
I will have to always write it above my PL block, and run this line with that PL block.before the first dbms_output call you can also issue dbms_output.enable() :
declare
my_var varchar(30);
begin
my_var:='&input';
dbms_output.enable();
for i in 1..5 loop
dbms_output.put_line('Hello '||my_var);
end loop;
end;
/This should always work, irrespective of how you SET SERVEROUT in sql*plus.Nope.
SQL> ed
Wrote file afiedt.buf
1 begin
2 dbms_output.enable();
3 dbms_output.put_line('TEST');
4* end;
SQL> /
PL/SQL procedure successfully completed.
SQL>dbms_output.enable is used to enable the output buffer (or set the size of it) on the server side of things. It can't influence the client application into retrieving and displaying the output from the buffer, even if that is SQL*Plus. ;) -
Set serveroutput on handling at Package/Procedure.
Hi,
Can we handle the set serveroutput on in package it self ?, what is the scenario we need to do for this.
I need to print some values after executing the package automatically.... please let me know further more information requried.
please let me know what DBMS_OUTPUT.ENABLE(10000000) will be do...?
Thanks,
Pavan KDBMS_OUTPUT.ENABLE(10000000) will turn on dbms_output, but unless the client knows to check for output you won't see anything.
To make SQL*Plus poll for output you need to use the SET SERVEROUTPUT ON SQL*Plus command to tell SQL*Plus to look for output. You could then use DBMS_OUTPUT.DISABLE to turn it off programatically until you need it turned back on.
Otherwise you need to poll for output yourself by issuing calls to DBMS_OUTPUT.GET_LINE[s] -
hi
how can I use "SET SERVEROUTPUT ON" clause on toadSame as you would in SQL*Plus: Simply type SET SERVEROUT ON in the SQL editor and run with F5.
Alternatively there's a button on the DBMS_OUTPUT desktop panel which should light up green. Output will then be generated when the statement is run with F9.
Maybe you are looking for
-
How can i delay the present of direct connected route?
Hi, I got 2 3550SMI switch interconnecting by Etherchannel. Each 3550 has an uplink to its upstream router (R1-SW1=SW2-R2). R1 and R2 connects to the remote site routers (say R3 and R4). With EIGRP redistribute connected, R1 update the direct connect
-
I'm trying to create a form in Acrobat 9. Source document is a Word doc. I'm getting an error message that Acrobat is unable to open the document and to check to see if I have read permission. Yes, I have full permissions on the source doc - in fact
-
How do you integrate LyrisHQ Opt-in form code in BC so that it works?
I created an opt-in form using the LyrisHQ platform and tested it in FF, IE and Chrome and it works. However, when I put the code on a page in BC it does not work and I do not get any error messages when I click on the submit button. Here is the code
-
How Do I create a Modular Function for use with Event Listeners
OK I'm very new to AS3 and I'm curious as to how to get modular functions to work in AS3. for instance if I have this code: function snowfall(snowflake:MovieClip, movement:Number):void snowflake.y = movement; snowfall(snowflake1_mc, 10); snowfall(sno
-
Data Mart and Data Extraction from an Infocube
Can a data mart which is built on one Infocube in BW support delta extraction? We have two separate BW systems and are trying to extract data from one Infocube in one BW (Source) and load it to one Infocube in another BW(Target)? We have built a data