using DBMS_OUTPUT

Oracle 11.2.0.1

Windows

I wrote this down below output required from scott.emp table:

declare

number of xdept: = null;

totsal number: = 0;

Start

for c (select empno, ename, sal, deptno from emp by deptno order) loop

If xdept is not null and xdept! = c.deptno then

dbms_output.put_line('---');

totsal: = 0;

end if;

dbms_output.put_line(c.empno ||) '  ' || c.Ename | '  ' || c.DEPTNO | '  ' || c.SAL | '  ' || totsal);

xdept: = c.DEPTNO;

totsal: = totsal + c.SAL;

end loop;

end;

7782 10 2450 CLARK 0

7839 10 5000 2450 KING

7934 10 1300 7450 MILLER

-----------------------------------------

7566 20 2975 JONES 0

7902 20 3000 2975 FORD

7876 20 1100 5975 ADAMS

7369 20 800 7075 SMITH

7788 20 3000 7875 SCOTT

-----------------------------------------

7521 WARD 30 1250 0

7844 30 1500 1250 TURNER

7499 30 1600 2750 ALLEN

7900 30 950 4350 JAMES

7698 30 2850 5300 BLAKE

7654 30 1250 8150 MARTIN

PL/SQL procedure successfully completed.

But I need something like this:

7782 2450 10 CLARK

7839 10 5000 KING

7934 10 1300 7450 MILLER

-----------------------------------------

7566 20 2975 JONES

7902 20 3000 FORD

7876 20 1100 ADAMS

7369 SMITH 20 800

7788 20 3000 7875 SCOTT

-----------------------------------------

7521 WARD 30 1250

7844 30 1500 TURNER

7499 30 1600 ALLEN

7900 JAMES 30 950

7698 30 2850 BLAKE

7654 30 1250 8150 MARTIN

that is, I want to show the wise sum Department of such sal that displayed in the desired output with a way lined up please.

Thank you.

Try this:

set serveroutput ON
set feedback off
set line 300
DECLARE
 v_name char(8);
 v_emp  char(5);
 v_sal  char(10);
 v_total char(10);
 v_deptno char(4);
BEGIN
   FOR c
      IN (WITH temp AS
                  (SELECT empno
                         ,ename
                         ,deptno
                         ,sal
                         ,SUM (sal) OVER (PARTITION BY deptno ORDER BY ename)
                             total
                         ,LEAD (deptno)
                             OVER (PARTITION BY deptno ORDER BY ename)
                             n
                     FROM emp
                   ORDER BY deptno)
          SELECT empno
                ,ename
                ,deptno
                ,sal
                ,CASE WHEN n IS NULL THEN total END AS total
            FROM temp)
   LOOP
      v_name := c.ename;
      v_emp := c.empno;
      v_deptno := c.deptno;
      v_sal := c.sal;
      v_total := c.total;
      dbms_output.put_line(v_emp || '  ' || v_name || '  ' || v_deptno || '  ' || v_sal || '  ' || v_total);
      IF c.total IS NOT NULL THEN
       dbms_output.put_line('------------------------------------------');
      END IF;
   END LOOP;
END;
/

Tags: Database

Similar Questions

  • Impression of the empty spaces using dbms_output.put_line

    There is a single string get dynamically generated. Generation, it may or may not contain white spaces at the beginning. Then I try to print it on standard i/o using the DBMS_OUTPUT. PUT_LINE. But if there is some of the spaces in the string, they are ignored. Is there another way to print the exact string that is?

    Hello..

    It depends on the configuration of your client... you can set the option parameter serveroutput wrap...

    set serveroutput on size 100000 for wrap;
    begin
      2    dbms_output.put_line('  Hello world.');
      3  end;
      4  /
      Hello world.
    
    PL/SQL procedure successfully completed.
    
  • String DBMS_OUTPUT buffer limit

    Hellou everyone

    DECLARE
    y varchar2 (32000): = RPAD('x',1000,'*'); -WORK
    z varchar2 (32000): = RPAD('x',1001,'*'); -DOES NOT WORK
    BEGIN
    dbms_output.put_line (length (y));
    dbms_output.put_line (y);
    dbms_output.put_line (length (z));
    dbms_output.put_line (z);
    END;

    I need a part of debugging and code when the string is Length > 1000 then error pops up:

    ORA-06502: PL/SQL: digital or value error: character string buffer too small
    ORA-06512: at "SYS." DBMS_OUTPUT", line 148
    ORA-06512: at line 2

    I don't know if there is some limmitation for the length of the string in put_line in documentation is the obly buffer size
    I tried to use dbms_output.enable (1000000) - but the same result

    I tried to use DBMS_OUTPUT. GET_LINE, but no results :(
    I can insert the value to the table or file, but I want to know why this limitation.

    I was looking on the forum but have not found anything.

    Thanks for the reply.

    Zoffo

    What version of Oracle are you using? This information must be in each original position. Before 10 g dbms_output had a documented length 255 bytes limit.

    You posted pl/sql runs without error on my 10.2.0.5 system:

    MPOWEL01@UT1> @t15
    1000
    x*******************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ****************************************
    1001
    x*******************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    ********************************************************************************
    *****************************************
    
    PL/SQL procedure successfully completed.
    

    HTH - Mark D Powell.

    PS - set serveroutput size 1000000 included before your pl/sql code

    Edited by: Mark D Powell on 31 August 2012 06:16

  • view the output of dbms_output statement in Toad

    Hi expert,

    I use dbms_output instruction in proceudre and run it into a toad, but he must run ' set serveroutput we "display output statement dbms_output.

    But how can I achieve this functionality in Toad.

    Thank you very much

    >

    Hello

    I use dbms_output instruction in proceudre and run into a frog, but it
    should run "set serveroutput on" to display the output of statement dbms_output.
    But how can I achieve this functionality in Toad.

    At the bottom of your window, there are number of tabs. One of them is
    DBMS_Output. There is a small red button on the left side. Click on this button.
    It turns green. Then, your output is visible - you can click on it and scroll
    upward through your results.

    In the future, ask questions of Toad in a forum of Toad.

    HTH,

    Paul...

  • DBMS_OUTPUT

    Hello

    I am running a batch that is written in pl/sql. I use dbms_output to show progress in the command prompt. But it only prints after the completion of the whole process. But I need to print the line once it is reached. For example in the next block, as soon as I run the block I need to print 'treatment stage1... '. "and say step 1 takes 10 minutes to complete, after 10 minutes I need to print 'treatment stage2... '. ».

    Is this possible? Kindly share your ideas.

    That is to say
    Start
    dbms_output.put_line ('treatment stage1...');
    Stage1;
    dbms_output.put_line ('treatment stage2...');
    Stage2;
    dbms_output.put_line ('treatment stage3...');
    Stage3;
    dbms_output.put_line ('treatment stage4...');
    Stage4;
    dbms_output.put_line ('treatment stage5...');
    Stage5;
    dbms_output.put_line ('process is complete...');
    end;

    Thank you
    Jaggyam

    Example code for the batch.

    Batch job
    ---------
    sqlplus @Sqlbatch.sql > Sqlbatch.log
    
    Sqlbatch.sql
    ----------------
    Scott/[email protected]
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    WHENEVER OSERROR EXIT
    ALTER SESSION SET NLS_LANGUAGE = English;
    ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
    set timing on
    set Serveroutput ON SIZE 99999;
    set linesize 250
    
    begin
    dbms_output.put_line('Start of stage1');
    end;
    
    Stage1
    
    begin
    dbms_output.put_line('Start of stage2');
    end
    
    Stage2
    
    begin
    dbms_output.put_line('End of batch job'||systimestamp);
    end
    
  • monitor the dbms_output buffer

    Database Oracle 10.2.0.4

    I have a way to control what a session is dbms_output buffer?

    A developer used dbms_output.put_line as a technique of 'connection' and now I'm trying to find a way to see what the application connects.

    Any hel appreciated.

    Concerning

    Claire wrote:
    Database Oracle 10.2.0.4

    I have a way to control what a session is dbms_output buffer?

    N ° wait that the PL/SQL code ends & control is returned to the client.

  • use of the SYS prefix in front of dbms.output)

    Hi all

    Maybe it's stupid. But I have a question what is the difference between the following two:

    DBMS_OUTPUT. PUT_LINE ('TEST');
    AND
    SYS. DBMS_OUTPUT. PUT_LINE ('TEST');

    What is the use of the SYS prefix?

    Concerning
    Sylvie

    788844 wrote:

    Maybe it's stupid. But I have a question what is the difference between the following two:

    DBMS_OUTPUT. PUT_LINE ('TEST');
    AND
    SYS. DBMS_OUTPUT. PUT_LINE ('TEST');

    Not stupid at all. It is a problem of scope-resolution.

    All programming languages have the scope-resolution. You are referring to a call (method, function, procedure, etc.). The system (compiler or at a time of engine performance) needs to understand exactly what you are doing reference, in order to execute this call.

    In the case of PL/SQL, PL/SQL engine will use first of all the local scope - in other words, objects (procedures, functions, variables, etc.) defined in the schema, and a unit of current code.

    If it fails to resolve the reference to appeal, it seems within the reach of the public.

    Dbms_output.put_line () is a call reference package. So the 1st check would be local control. This package exists in the current schema? Is there a local synonym that can be used?

    In case of failure, scope becomes public. Is there a public reference (synonymous in this case) that solves that?

    The answer for DBMS_OUTPUT is Yes - and this public synonym refers to the package belonged to the SYS schema.

    If you had a local package with the same name, or a local synonym, then that would have been used.

    When you encode now SYS. Dbms_output.put_line () instead, you explicitly specify the scope to the PL/SQL engine. You say that you're referring to the DBMS_OUTPUT object belonged to the SYS schema.

    Both methods have some advantages and disadvantages.

    Simplistically, the implicit scope (where leave you the engine to search for the object you are referencing) offers more flexibility. Let's say you need to change the behavior of the DBMS_OUTPUT - do it for example also write output to a log file. You can create your own package DBMS_OUTPUT with the exact same interface as the SYS. DBMS_OUTPUT package. Inside of your custom package, you can write the output to a log file and then call the SYS. DBMS_OUTPUT package to do its part.

    The original source code using DBMS_OUTPUT.put_line () works unchanged. Is what you have now introduced a local reference meets the criteria of the scope - and your local DBMS_OUTPUT package is now used instead.

    Scope explicit can claim to be safer. That no person shall "divert" calling your code by manipulating scope of the resolution - and do the above and create a custom of DBMS_OUTPUT package. But it also makes the code much more rigid.

    In general in PL/SQL - extended implicit is desirable because it provides the flexibility that is often necessary. When writing "of trust' global code that does cool stuff user and must be trusted to always do the right thing, then brought explicit should consider instead.

  • How to get the output (!) during procedure-run / RAS dbms_output.put_line

    Hello again,

    during a migration script written in plsql, we print several status information on-screen using dbms_output.put_line.

    for your information:

    the script commits each lines x during a massive update. A commit is carried out whenever I want to have the output: Timestamp + number of lines committed themselves.

    Unfortunately the output by dbms_output.put_line is emptied to sqldeveloper once the procedure is complete.
    So I have all the time after the migration is complete, but if possible I need the information when it is put into the stack of the dbms_output.
    Is it possible to flush the output while the process is still ongoing? Are the alternatives to dbms_output.put_line who could help?

    Oracle is 10.2.0.4

    Thank you very much
    Andreas

    Published by: Andreas s. the 11.03.2011 01:38

    Note:
    Messages sent using the DBMS_OUTPUT are not actually sent until full subprogramme of the shipment or the relaxation. > There is no mechanism to flush the output during execution of a procedure.

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14258/d_output.htm

    you could just write your output to a table?

  • possibility of improvement in dbms_output.put_line... !

    Hey,.

    I'm having a strange customer requirement.
    I use dbms_output.put_line to exit. But I was getting error of buffer flow.
    Then, I used to write the log to a file but when utl_file due to a problem of permission for the log file directory to the computer unix FTP, I can't use utl_file.

    Is it possible in dbms_output than if flow of buffer error raise at this time
    2nd log file generate the new name and the remaining log data written to the new log file.

    My code is generally inferior to...
    ---------------------------------------------------------------------------------------------------------------
    SET OF BUFFER 1000000
    SET SERVEROUTPUT ON
    coil LMG_DBmigration_CP_DATA_Log.log

    Declare

    Start
    Stmnts for DBMS_OUTPUT. PUT_LINE;
    Stmnts for DBMS_OUTPUT. PUT_LINE;
    Stmnts for DBMS_OUTPUT. PUT_LINE;
    :
    :
    :
    Stmnts for DBMS_OUTPUT. PUT_LINE;

    end;
    /
    spool off
    "exit";
    ---------------------------------------------------------------------------------------------------------------

    no idea...?

    Rgds,
    PC

    As long as you put dbms_output.enable (buffer_size-online NULL) in the begin... END of block (before first dbms_output.put_line is running), it won't be a problem.

  • DBMS_OUTPUT in BULK COLLECT FORALL

    Hello

    I'm trying to figure out how I can output using DBMS_OUTPUT. Put_line in a BULK COLLECT / FORALL update?

    Example:

    SEARCH REF_CURSOR BULK COLLECT INTO l_productid, l_qty
    ForAll indx in l_productid.first... l_productid. Last


    Aa products update
    The value of aa. LastInventorySent = l_qty (indx)
    Where aa.productid = l_productid (indx);

    DBMS_OUTPUT. Put_line ("ProductID: ' |") l_productid (indx) | "QTY: ' |" l_qty (indx);

    Is this possible? If so how I can accomlish this?

    Thank you

    S
    FETCH REF_CURSOR BULK COLLECT INTO l_productid,l_qty
    forall indx in l_productid.first..l_productid.last
    Update products aa
    Set aa.LastInventorySent = l_qty(indx)
    Where aa.productid = l_productid(indx);
    for indx in 1..l_qty.count loop
     DBMS_OUTPUT.PUT_LINE('ProductID: ' || l_productid(indx)|| ' QTY: ' || l_qty(indx);
    end loop;
    

    SY.

  • Developer SQl 2.1.0.62 - dbms_output.put_line

    When you try to use dbms_output.put_line sure seems to me keep receiving messages in the Logging tab and example Page would be:

    Index of invalid column for the SEVERE 96 516 oracle.dbtools.db.DBUtil

    This seems to occur when you perform a simple anonymous block with a command unique dbms_output.put_line.

    I tried SQL Developer of fence and using a new session, but same problem.

    What is an installation problem or something else?

    Hello

    The
    "" SERIOUS 103 26830 oracle.dbtools.db.DBUtil ORA-02248: invalid option for ALTER SESSION ".
    is a question of 9.2 is buggy and noted here:
    After the db will apear connection error.

    -Turloch

  • DBMS_Output.put_line does not print in one line

    Hi people,

    I use 'DBMS_Output.put_line' in my procedure for output. Here is the code:

    Dbms_output.put_line ('LOGIT_T. detail records for Bill :'|| v_count_act |', detail of records for ball :'|| v_count_bal |', updated records for Bill :'|| v_updat_act |', update the records for the dance :'|| v_updat_bal |', Total records for Bill :'|| v_count_act |', Total records for Prom :'|| v_count_bal);

    When the procedure runs, it displays the output as shown below:

    LOGIT_T. records detailed bill: 619, detail records for the ball: 324, update records
    to the Act: 0, updated records for bal: 0, Total of records for Bill: 693, Total of records for
    Ball: 410

    Therefore, when you insert this whole line in the table, it only inserts the following text. Therefore, does not take into account the rest of the text (field of table width is 2000 bytes):

    LOGIT_T. records detailed bill: 619, detail records for the ball: 324, update records

    Looks like, it's automatically wrapping the text to the next line. While I want the output above on a single line, as shown below, and to be inserted in my table of the entire text:

    LOGIT_T. records detailed bill: 619, retail for Prom: 324, updated records records for Bill: 0, records update for Prom: 0, Total of records for Bill: 693, Total of records for Prom: 410

    No idea how to do this? The parameters or configuration I'm missing here?

    Hope I made sense above and clearly describes my situation.
    Thanks in advance guys!

    in sqlplus, you can use set linesize:

    SQL > set serverout on
    SQL > set linesize 10
    SQL > exec dbms_output.put_line ("' is a line of text that exceeds 10 characters");
    It is a
    line
    text which
    exceed the 10
    characters

    PL/SQL procedure successfully completed.

    SQL > set linesize 132
    SQL > exec dbms_output.put_line ("' is a line of text that exceeds 10 characters");
    It is a line of text that is longer than 10 characters

    PL/SQL procedure successfully completed.

  • view the results of appeal required webservice

    Hi expert,

    I took a familiar approach of post of billy Re: PLSQL webservice call to invoke a web service. Is it possible to display the return (xmlResponse) this function or using DBMS_OUTPUT.put_line (xmlResponse) to display the data if the data size is large enough, I need to display the format returned xmlResponse to analyze in a table or best way to... any ideas there?


    Thank you


    Nick

    You can write the CLOB ("soapResponse" from Billy code) in a file using DBMS_XSLPROCESSOR.clob2file ().

    You can then open it with an XML Editor to understand its structure.

  • run a script to a page

    APEX 4.2, Oracle12c Oracle Linux

    I have a button on a page of LOVs cascading and I know how to refer to the final, I use the id of the list, something like P40_DSET.  The button should on this page or on a white page subject to start an existing load script SEGYLOAD. LOADDATASET (P_DATASET_ID = > 'P40_DSET', P_MODE = > 'INIT').  I found a way to put the script

    in the APEX put button in place, but I would prefer that to initiate implementation using the name, essentially from another process or it works online but by name, do not put code in the APEX.  How to do this?

    HustlingHare wrote:

    Then try:

    My procedure in the post process is:

    Start

    apex_debug.log_dbms_output ();

    dbms_output.put_line ('start loaddataset');

    idsud.segyload.LoadDataSet (p_dataset_id =>: p40_dset, p_mode => 'INIT');

    dbms_output.put_line ('loaddataset finished');

    end;

    where the procedure, idsud.segyload.loaddatase, was performed successfully in SQLWorkshop

    I enabled Debug, you click on the vision correction and got the following at the end of loading;  It seems that that process but I couldn't out put_line in this newspaper. The loaddataset procedure uses dbms_output.putline for its release summary so I see a lot of lines of the procedure generated in this debug log?  I got the success message of the post on the screen process, but the process is too fast for her to have actually run.

    4 -

    .. .and too slowly for her not be called at all. Are there no error message indicating that it could not.

    Referring to a suggestion in your other thread, the procedure has no bad exception handling which could hide all these errors?

  • View the results of a slider control

    HI, I'm suggling on this pl/sql, because I just started learning a few weeks ago. Basically what this pl/sql is check

    in my article "the time" to see if any time is not in the current time format and if it finds one it should display only and then someone can go and check.

    Firstly this my_table has 3 different columns which makes it the primary key, so I need display the columns so that the administrator can find the

    incorrect data easily in the time column.

    These 3 columns that actually the primary key are 'sid', "setid" and "sentry".

    I have created a slider and possesses the top loop to check all the my_table data but I do not know how to dmbs_output

    all results at once. In the results, I need to display all the columns in key primary and thus 3 under and this column that the data is.

    IF SQLCODE =-01858

    THEN

    Dbms_output.put_line (-);

    Can someone help me please.  Here are my codes

    DECLARE

    v_result varchar2 (4000);

    v_key1 varchar2 (10 byte);

    whole v_key2;

    whole v_key3;

    cursor c_get_times

    is

    SELECT sid, setid, Sentinel, time FROM my_table;

    c_get_times_row c_get_times % ROWTYPE;

    BEGIN

    TIMES a c_get_times LOOP

    v_key1: = times.sid;

    v_key2: = times.setid;

    v_key3: = times.sentry;

    SELECT TO_DATE (times.time, "HH24") IN v_result FROM my_table;

    END LOOP;

    OPEN c_get_times.

    LOOP

    EXTRACT the c_get_times in c_get_times_row;

    EXIT WHEN c_get_times % NOTFOUND;

    END LOOP;

    EXCEPTION

    WHILE OTHERS

    THEN

    IF SQLCODE =-01858

    THEN

    Dbms_output.put_line ();

    ELSIF SQLCODE =-01851

    THEN

    Dbms_output.put_line ('invalid value for minutes");

    ON THE OTHER

    Dbms_output.put_line (' failed with another unknown error: ' |) SQLERRM);

    END IF;

    END;

    If you can create the object in your schema, create the function below and the race below query it will give a correct result. I think that's the test objective you ask, otherwise do not use DBMS_OUTPUT. Just create the function and run the select statement.

    FUNCTION to CREATE or REPLACE date_chk (p_value VARCHAR2, VARCHAR2 p_format)

    RETURN NUMBER

    AS

    v_val1 NUMBER (10);

    T_DATE DATE;

    BEGIN

    T_DATE: = TO_DATE (p_value, p_format);

    RETURN 1;

    EXCEPTION

    WHILE OTHERS THEN

    IF SQLCODE =-01858 THEN

    RETURN 0;

    END IF;

    END;

    SELECT the sid,

    SetID,

    Sentinel,

    timeval

    OF test_time

    WHERE date_chk(timeval,'HH24:MI') = 0;

Maybe you are looking for