PL/SQL set serveroutput
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
-Dave
David,
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
Similar Messages
-
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 -
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. -
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
thanksHow 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 -- -
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 -
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 -
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. -
Any relation b/w set serveroutput on size 1000000 and utl_file
Hi All,
pls tell is any relation b/w set serveroutput on size 1000000 and utl_file
Thank u.there is no relation between them
one is used to output text on the screen
where as the other is used to output text on the file.
dbms_output->Screen
utl_file->file -
Script path not used / set serveroutput
i set the directory in
database -> worksheet to the same directory like my sqplus SQLPATH.
but it looks like the worksheet is not use the directory entry.
when i start the script with the full pathname its working.
but ... then sqldeveloper tell me
ignore set serveroutput on... is ignored.... but no result is shown....
Version : 1.1.0.21
Build : Main-21.41
OS is Linux
Message was edited by:
ojehleThe preference for the path is not working, this is a bug and is logged.
For set server output: The output is written to the DBMS Output tab and you need to use the toggle on that screen to set server output on.
Sue
Maybe you are looking for
-
Itunes does not see ipod touch
Upgraded Itunes11.0.0.163 for Windows 7 64 bit. Running on Asus Laptop. Windows 7 Ultimate 64 bit. Itunes does not recognize ipod toch Gen 4 updated to ios 6 Totally uninstalled and manually cleaned all itunes software several times. Reset iPod tou
-
Hi Could you please let me know the table where I can check all open down payment request with indicator F? Thanks Sweta
-
NFS does not recognize security mode
Hello, I want to add kerberos authentication to nfs. The kerberos client works, since I can authenticate principals and gt tickets. The keytab file for nfs/my.host looks like it should as described in the sysadmin manual. -bash-3.00# klist -k Keytab
-
Can not programmatically undeploy the application from a Weblogic Server
Hi experts, I have a weblogic client application that is used to deploy/undeploy the application to weblogic server. The following code call undeploy() method to undeploy the application. But I still can see the application shown in the admin console
-
Periodic automatic data connection (unwanted)
This sneaky little 5800 initiates a data connection automatically from time to time and upon startup. I cannot tell which program is communicating let alone whom with. It causes around 10KB of traffic on EDGE (I use the phone in GSM mode), and I can