Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQLPLUS Report with Carry forward summary on each page.

Phil in SydneyApr 12 2018 — edited Apr 12 2018

Hi there,

I have a table which contains lots of records. I use sqlplus to spool the result.

set newpage 0 feedback off

set pagesize 15 linesize 100

break on grp skip page

compute sum of amt on grp

with table_sales (id,grp,amt) as (

  select 1,1,10 from dual

  union all select 1,1,10 from dual

  union all select 2,1,20 from dual

  union all select 3,1,30 from dual

  union all select 4,1,40 from dual

  union all select 5,2,50 from dual

  union all select 6,2,60 from dual

  union all select 7,2,70 from dual

  union all select 8,2,80 from dual

  union all select 9,2,90 from dual

  union all select 10,2,100 from dual

)

select id,grp,amt from table_sales;

<Page1>

        ID        GRP        AMT

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

         1          1         10

         1                     10

         2                     20

         3                     30

         4                     40

           ********** ----------

           sum             110

<Page 2>

        ID        GRP        AMT

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

         5          2         50

         6                     60

         7                     70

         8                     80

         9                     90

        10                  100

           ********** ----------

           sum            450

How can I put the summary 110 on Page 1 to the bottom of Page 2 as carry forward summary and add up together?

<Page 2>

        ID        GRP        AMT

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

         5          2         50

         6                     60

         7                     70

         8                     80

         9                     90

        10                  100

           ********** ----------

           sum             450    Sub-Total on Page 2

                                 110  CARRY FWD TOTAL on Page 1

          TOTAL           560  Grand Total on Page 2

Is that possible? It might not only 2 pages, might be many pages.

Any help or hints will be appreciated.

Phil

This post has been answered by Frank Kulash on Apr 12 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2018
Added on Apr 12 2018
7 comments
334 views