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

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 AM

    Try to put serveroutput statement before spool statement.
    Hope it helps you,
    Fabrizio

  • 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:
    ojehle

    The 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

  • 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...............  its not working for me on oracle 9i.

    hi, i have used SET SERVEROUTPUT ON , in my plsql but i am unable to see the output after the execution , iam using oracle 9i any reason for not displaying..

    DECLARE
    V_Empno     NUMBER(4)     :=     &EnterEmpNo;
    V_Ename          VARCHAR2(30);
    V_Deptno     NUMBER(2);
    V_Job          VARCHAR2(30);
    V_MGR          NUMBER(4);
    V_HireDate     DATE;
    V_Sal          NUMBER(7,2);
    V_Comm          NUMBER(7,2);
    BEGIN
         SELECT
         Ename, Deptno, Job, MGR, HireDate, Sal, Comm
         INTO
         V_Ename, V_Deptno, V_Job, V_MGR, V_HireDate, V_Sal, V_Comm
         FROM Emp
         WHERE Empno = V_Empno;
    DBMS_OUTPUT.PUT_LINE('The Details of Employee Number '||V_Empno||' Requested by You Are ...');
    DBMS_OUTPUT.PUT_LINE('The Employee Name : '||V_Ename);
    DBMS_OUTPUT.PUT_LINE('The Department Number : '||V_Deptno);
    DBMS_OUTPUT.PUT_LINE('The Designation : '||V_Job);
    DBMS_OUTPUT.PUT_LINE('The Manager Number : '||V_MGR);
    DBMS_OUTPUT.PUT_LINE('The Joining Date : '||V_HireDate);
    DBMS_OUTPUT.PUT_LINE('The Basic Salary : '||V_Sal);
    DBMS_OUTPUT.PUT_LINE('The Commission Earned : '||V_Comm);
    END;
    /

  • SET SERVEROUTPUT ON TOAD

    hi
    how can I use "SET SERVEROUTPUT ON" clause on toad

    Same 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.

  • 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 K

    DBMS_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]

  • How to use materialized view in stored procedure

    in my stored procedure I use couple of queries (see the script below). I want to create materialized views to replace these queries. Is it possible to achieve and how to achieve it in my case? thanks in advance
    set serveroutput on
    DECLARE
      v_cur_tid NUMBER(5):=0;
      v_cur_cs_attendance NUMBER(5):=0;
      v_cur_c_tot_enrolments NUMBER(5):=0;
      v_most_enrolments NUMBER(5):=0;
      v_least_enrolments NUMBER(5):=0;
      v_most_pop_cid NUMBER(5):=0;
      v_least_pop_cid NUMBER(5):=0;
      CURSOR class_cursor IS
    select
    id,
    name,
    max_attendees
    from
    class
    where
    id in (select distinct(event_id) from trainer_schedule where event_type='c' and is_active='y')
    order by id;
    BEGIN
    DBMS_OUTPUT.PUT_LINE('==================================================================================================================================');
    --print the report header
    DBMS_OUTPUT.PUT_LINE('Summary Report No.3: Training Class Active Schedules Summary Report');
    FOR r_class IN class_cursor LOOP
    --print the header or subsection
    select sum(enrolments) into v_cur_c_tot_enrolments from class_schedule where class_id = r_class.id;
    IF v_most_enrolments < v_cur_c_tot_enrolments OR v_most_enrolments = 0
    THEN v_most_enrolments := v_cur_c_tot_enrolments; v_most_pop_cid := r_class.id;
    END IF;
    IF v_least_enrolments > v_cur_c_tot_enrolments OR v_least_enrolments = 0
    THEN v_least_enrolments := v_cur_c_tot_enrolments; v_least_pop_cid := r_class.id;
    END IF;
    DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
    DBMS_OUTPUT.PUT_LINE('CLASS_ID: '  || r_class.id ||'     '|| 'CLASS_NAME: '  || r_class.name ||'     '||'CAPACITY: '  || r_class.max_attendees ||'     '||'TOTAL_ENROLMENTS: '  || v_cur_c_tot_enrolments);
    DBMS_OUTPUT.PUT_LINE(rpad('____________', 12) || lpad('____________', 12) || lpad('____________________', 20) || lpad('____________________', 20) || lpad('____________',12) || lpad('____________',12));
    DBMS_OUTPUT.PUT_LINE(rpad('SCHEDULE_ID', 12) || lpad('TRAINER_ID',12) || lpad('START_TIME', 20) || lpad('END_TIME',20) || lpad('ENROLMENTS',12) || lpad('ATTENDANCE',12));
    DBMS_OUTPUT.PUT_LINE(rpad('____________', 12) || lpad('____________',12) || lpad('____________________', 20) || lpad('____________________', 20) || lpad('____________',12) || lpad('____________',12));
    FOR r_cs IN (select id,to_char(start_time,'DD-MM-YYYY HH24:Mi') as start_time, to_char(end_time,'DD-MM-YYYY HH24:Mi') as end_time, enrolments from class_schedule where class_id = r_class.id order by id)
    LOOP
    select trainer_id into v_cur_tid from trainer_schedule where event_type='c' and event_id = r_cs.id;
    select count(training_session.id) into v_cur_cs_attendance
    from training_session, class_schedule
    where training_session.attended = 'y' and
    training_session.type='c'and
    to_char(training_session.start_time,'DD-MM-YYYY HH24:Mi') = to_char(class_schedule.start_time,'DD-MM-YYYY HH24:Mi') and
    class_schedule.id = r_cs.id;
    DBMS_OUTPUT.PUT_LINE(rpad(r_cs.id, 12) || lpad(v_cur_tid,12) || lpad(r_cs.start_time, 20) || lpad(r_cs.end_time,20) || lpad(r_cs.enrolments,12) || lpad(v_cur_cs_attendance,12));
    END LOOP;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
    DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
    DBMS_OUTPUT.PUT_LINE('MOST_POPULAR_CLASS:  '||v_most_pop_cid||'      TOTAL_ENROLMENTS_TO_DATE: '||v_most_enrolments);
    DBMS_OUTPUT.PUT_LINE('LEAST_POPULAR_CLASS: '||v_least_pop_cid||'      TOTAL_ENROLMENTS_TO_DATE: '||v_least_enrolments);
    DBMS_OUTPUT.PUT_LINE('==================================================================================================================================');
    END;
    /

    Hi,
    you could use Dynamic SQL /Execute immediate to run DDL from a stored procedure.
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/11_dynam.htm
    Could you please tell why do you want to create a materialized view in stored procedure ?
    How frequently you will runt this procedure . It would is better to create a MV once and use it.
    thanks

  • Set serveroutput on;

    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

  • 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 --

  • 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

  • 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

  • Two related questions: using htmldb_Get to call stored procedure and passing in an array of items

    I have the need to save dynamically generated ApEx items via AJAX.  I am using APEX_ITEM API to generate the items.  At run-time, I have no idea how many of items will be generated on the page, but I know that they will all have discreet and distinct "name" attributes, i.e. f01, f02, f03, etc.  As a basic example, if I have to generate a select list, I know that the "p_idx" parameter of the APEX_ITEM call is say "3", so all select lists that get generated will have a "name" attribute in the DOM of "f03", all text items will be "f01", etc.
    I want to save this data to the database via AJAX.  It is typical to call the standard htmldb_Get javascript function for use of an on-demand process, but I am interested in using the rarely-called-upon "procedure" and queryString" options of that javascript function so that I can build the queryString on the fly based on what is on the DOM when the tries to save the data they entered into these APEX_ITEM-generated items.  Does anyone have any good examples of how to use the "procedure" and "queryString" parameters of the htmldb_Get javascript function?
    I have found a smattering of some blogs, posts, etc. online related to this, but mostly just people regurgitating the documentation.  I found this post (https://forums.oracle.com/thread/2549237) which had a glimpse of hope to be able to pass an array (which is something I will need) as a parameter, but would like someone to sanity check this before I go down that road.
    Shane.
    ApEx 4.2.1

    Shane
    Since you mention you are on APEX 4.2  I would recommend using apex.server.process which is the documented replacement of the officially undocumented htmldb_Get.
    In the documentation it is set that the first parameter is the ajaxidentifier but it actually is the process name.
    The data object would be something like
    var lData ={f01 : get_value_array('f01')}
    Where get_value_array is
    function get_value_array(pColumnName) {
      var l_values =[];
      apex.jQuery('[name="'+pColumnName+'"]').each(
       function(){
        var l_value;
        l_value = apex.item(this.id).getValue();
        l_values.push(l_value);
      return l_values
    For a working example see this demo.
    Nicolette

  • Using VIEW inside a stored procedure

    Hi,
    So I have a View designed in one file that validates someone who is authorized.
    Then I have a stored procedure to display authorized stationeries created before a given date. Its takes a parameter @CreatedOn.
    How can I use VIEW in my stored procedure so I can display all the authorized which are set 1 before a given date?
    My VIEW:
    ALTER VIEW vw_AuthorizedStationeries AS
    SELECT Authorized
    FROM dbo.Stationeries
    WHERE Authorized = 1
    And my stored procedure:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)ASBEGINSELECTFROMENDGO
    Thanks!

    Try something like below, You need to replace CreatedDate column with appropriate date column in your table.
    1. Alter the view to get the required date:
    ALTER VIEW vw_AuthorizedStationeries AS
    SELECT Authorized, CreatedDate
    FROM dbo.Stationeries
    WHERE Authorized = 1
    2. Alter SP:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
    AS
    BEGIN
    SELECT Authorized
    FROM vw_AuthorizedStationeries
    WHERE CreatedDate <= @CreatedOn
    END
    GO
    OR
    You can pull required information directly from your table:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
    AS
    BEGIN
    SELECT Authorized
    FROM dbo.Stationeries
    WHERE CreatedDate <= @CreatedOn and Authorized = 1
    END
    GO
    If this post answers your query, please click "Mark As Answer" or "Vote as Helpful".

  • Using temporary tables in stored procedures

    Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
    What is the way of using temporary tables in stored procedures?

    It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
    But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
    Example:
    Create or Replace Procedure Proc_TestDynamicSQL is
    Begin
    Execute Immediate 'Create table myTable as select * from user_tables' ;
    Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
    End;
    In this case, Oracle wouldn't care about the table references during compilation.

Maybe you are looking for

  • Email attachments won't open.

    Just ran the latest update to the iPad and now my email attachments are trying to open in airsharing.  How do I change the default reading application in my email?

  • Error when deleting applet from card

    I have a JCOP 41 card, where I am working with. I use the JCOP plugin (3.1.0.5) within Eclipse (SDK 3.0.1). I've uploading some applets to my card, but there resides 1 applet on my card that I can't remove anymore, the other can be removed correctly.

  • Disabling Access Keys in Safari

    Access keys in Safari tend to interfere with the Emacs-style shortcuts used in text-boxes. So, it can happen that while your editing you accidentally press some access key, thus losing all your changes. So is there a way to at least disable access ke

  • WLC Flex7500 in HA on VLAN1

    Hi guys. We provide wireless with a couple of Flex7500 in HA Deployment. Both WLC are in LAG (10Gx2) to a Nexus 7K. Management and Redundancy-Management Interface are untagged while in N7K their subnet IP belongs to VLAN1. (I know VLAN1 is not a best

  • To which level serial numbers can be tracked in WM

    Hi all, i just want to know , to which level serial numbers can be tracked in WM. is it posible to tack at bin level or it is limited to sloc level in MM ? Regards Viran