Computing sums

Does any1 know how to compute sums and averages from a master block into a detail block using PL/SQL triggers?
Thanks for your help.

Hi,
If you have Forms later than 5.0, you have the possibility to have summary fields.
Using triggers is a bit tricky, yet here's how to do.
Make a package spec program unit, named, say vars, where you may have variables visible throughout all form code. So, there you'll have declared:
old_numval number;
(used to store the value of an item used for calculating the sum prior to the item modification).
In the when-new-item-instance of the item used to calculate the sum you'll have:
vars.old_numval:=nvl(:your_block.your_summarised_item, 0);
In the when-validate-item for the summarised item:
:your_summary_block.x_summary_item:=:your_summary_block.x_summary_item-vars.old_numval+nvl(:your_block.your_summarised_item, 0);
I use nvl due to the fact that if you have null items those would give a null sum.
This is how to calculate a sum field. An average field would be almost the same thing.
One matter is that you'll usually have to have all the querried records fetched (which might be a problem if there are many records).
Best of luck,
BD.

Similar Messages

  • Simple PL/SQL Report - Using Break on and Compute Sum - Not So Simple

    Good morning, All:
    I have a simple pl/sql report that is not so simple. Basic on the code below, would like to add a blank line/row after the resulting "sum" row to make it easier to read. Any and all help would be appreciated.
    Thank you.
    Preston@Large
    Code:
    =======================
    BREAK ON ALM_OG_CAMPAIGN_CODE
    COMPUTE SUM OF ALM_OG_AMOUNT ON ALM_OG_CAMPAIGN_CODE
    set linesize 1024
    set pagesize 60
    set newpage 0
    set serveroutput on
    SPOOL &so_outfile;
    ttitle center 'Wayne State University' skip 1 Left 'WSU Online Giving Essentials Report' skip 2
    select TO_CHAR(sysdate, 'mm/dd/yyyy hh:mm AM') "Report Date" from dual;
    CLEAR COLUMNS
    column ALM_OG_ACCI_CODE heading "ACCI|CODE" format a10
    column ALM_OG_AMOUNT heading "AMOUNT|DONATED" format $999,999,999.99
    column ALM_OG_CAMPAIGN_CODE heading "CAMPAIGN|CODE" format a14
    select
    ALM_OG_CAMPAIGN_CODE,
    ALM_OG_ACCI_CODE,
    ALM_OG_AMOUNT
    From WSUALUMNI.WSU_ONLINE_GIVING_TABLE
    ORDER BY ALM_OG_CAMPAIGN_CODE;
    CLEAR COLUMNS
    spool off
    Output:
    WSU Online Giving Essentials Report
    Report Date
    ======================
    06/05/2009 10:06 AM
    1 row selected.
    Wayne State University
    WSU Online Giving Essentials Report
    CAMPAIGN ACCI AMOUNT
    CODE CODE DONATED
    ====== ======== ==========
    sum $560.00
    NUR 444814 $10.00
    ***** =======
    sum $10.00
    PHS 445216 $10.00
    ***** =======
    sum $10.00
    PRES 445211 $450.00
    445211 $60.00
    445211 $250.00
    ***** =======
    sum $760.00
    SBA 444216 $10.00
    ***** =======
    sum $10.00
    SSW 444469 $10.00
    ***** =======
    sum $10.00

    Prestone,
    Welcome to the Forum!
    I have used skip 2 lines you can use 1
    SQL> break on job report skip 2
    SQL> compute sum of sal on job report
    SQL> select job , sal from emp order by job ;
    JOB              SAL
    ANALYST         3000
                    3000
    sum             6000
    CLERK           1300
                     950
                     800
                    1100
    sum             4150
    MANAGER         2850
                    2975
                    2450
    sum             8275
    PRESIDENT       5000
    sum             5000
    SALESMAN        1500
                    1250
                    1250
                    1600
    sum             5600
    14 rows selected.READ
    Quick SQL*Plus Guide
    http://download.oracle.com/docs/cd/B14117_01/server.101/b12171/toc.htm
    SQL*Plus Reference
    http://download.oracle.com/docs/cd/B14117_01/server.101/b12170/toc.htm
    SS

  • SQL*Plus: compute sum of tablespaces; incorrect figures

    Hi,
    I wonder if someone would be interested in checking the below script.
    It is from Darl Kuhn's book 'Pro Oracle Database 11g Administration' (page 81) , and the code can be freely
    downloaded from Apress' website, so I guess it's OK to post it here. I assume it's a standard script most DBA's have, anyway.
    SET PAGESIZE 300 LINES 132 ECHO OFF VERIFY OFF FEEDB OFF SPACE 1 TRIMSP ON
    COMPUTE SUM OF a_byt t_byt f_byt ON REPORT
    BREAK ON REPORT ON tablespace_name ON pf
    COL tablespace_name FOR A17   TRU HEAD 'Tablespace|Name'
    COL file_name       FOR A40   TRU HEAD 'Filename'
    COL a_byt           FOR 9,990.999 HEAD 'Allocated|GB'
    COL t_byt           FOR 9,990.999 HEAD 'Current|Used GB'
    COL f_byt           FOR 9,990.999 HEAD 'Current|Free GB'
    COL pct_free        FOR 990.0     HEAD 'File %|Free'
    COL pf              FOR 990.0     HEAD 'Tbsp %|Free'
    COL seq NOPRINT
    DEFINE b_div=1073741824
    select * from (
    SELECT 1 seq, b.tablespace_name, nvl(x.fs,0)/y.ap*100 pf, b.file_name file_name,
      b.bytes/&&b_div a_byt, NVL((b.bytes-SUM(f.bytes))/&&b_div,b.bytes/&&b_div) t_byt,
      NVL(SUM(f.bytes)/&&b_div,0) f_byt, NVL(SUM(f.bytes)/b.bytes*100,0) pct_free
    FROM dba_free_space f, dba_data_files b
    ,(SELECT y.tablespace_name, SUM(y.bytes) fs
       FROM dba_free_space y GROUP BY y.tablespace_name) x
    ,(SELECT x.tablespace_name, SUM(x.bytes) ap
       FROM dba_data_files x GROUP BY x.tablespace_name) y
    WHERE f.file_id(+) = b.file_id
    AND   x.tablespace_name(+) = y.tablespace_name
    and   y.tablespace_name =  b.tablespace_name
    AND   f.tablespace_name(+) = b.tablespace_name
    GROUP BY b.tablespace_name, nvl(x.fs,0)/y.ap*100, b.file_name, b.bytes
    UNION
    SELECT 2 seq, tablespace_name,
      j.bf/k.bb*100 pf, b.name file_name, b.bytes/&&b_div a_byt,
      a.bytes_used/&&b_div t_byt, a.bytes_free/&&b_div f_byt,
      a.bytes_free/b.bytes*100 pct_free
    FROM v$temp_space_header a, v$tempfile b
      ,(SELECT SUM(bytes_free) bf FROM v$temp_space_header) j
      ,(SELECT SUM(bytes) bb FROM v$tempfile) k
    WHERE a.file_id = b.file#
    ORDER BY 1,2,4,3);The thing is, if I run this on our production database (Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi)
    I get individually correct rows, but the sumline is incorrect:
    Tablespace        Tbsp %                                           Allocated    Current    Current File %
    Name                Free Filename                                         GB    Used GB    Free GB   Free
    plenty of rows like this here...
    SCDAT               12.4 /oracle/SCDT/data/SCDT/c_scdat01.dbf         10.000      8.944      1.056   10.6
                             /oracle/SCDT/data/SCDT/c_scdat02.dbf         10.000      8.875      1.125   11.3
                             /oracle/SCDT/data/SCDT/c_scdat03.dbf         10.000      8.820      1.180   11.8
                             /oracle/SCDT/data/SCDT/c_scdat04.dbf         10.000      8.819      1.181   11.8
                             /oracle/SCDT/data/SCDT/c_scdat05.dbf         10.000      8.787      1.213   12.1
                             /oracle/SCDT/data/SCDT/c_scdat06.dbf         10.000      8.792      1.208   12.1
                             /oracle/SCDT/data/SCDT/c_scdat07.dbf         10.000      8.508      1.492   14.9
    then the summing row shows (for AllocatedGB, CurrentGB and CurrentFreeGB)
                                                                     1,155.000     858     179The thing is that this isn't correct. Firstly; current free isn't equal to allocated - currently used.
    Secondly, if I sum all the rows in a spreadsheet, they are
    1171.668 931.897 239.758
    Do you get similiar results, i.e. the script sums incorrectly?
    If yes, can anybody spot the error? I can't..
    Thanks very much!

    Slow_moe wrote:
    Tablespace        Tbsp %                                           Allocated    Current    Current File %
    Name                Free Filename                                         GB    Used GB    Free GB   Free
    plenty of rows like this here...
    SCDAT               12.4 /oracle/SCDT/data/SCDT/c_scdat01.dbf         10.000      8.944      1.056   10.6
    /oracle/SCDT/data/SCDT/c_scdat02.dbf         10.000      8.875      1.125   11.3
    /oracle/SCDT/data/SCDT/c_scdat03.dbf         10.000      8.820      1.180   11.8
    /oracle/SCDT/data/SCDT/c_scdat04.dbf         10.000      8.819      1.181   11.8
    /oracle/SCDT/data/SCDT/c_scdat05.dbf         10.000      8.787      1.213   12.1
    /oracle/SCDT/data/SCDT/c_scdat06.dbf         10.000      8.792      1.208   12.1
    /oracle/SCDT/data/SCDT/c_scdat07.dbf         10.000      8.508      1.492   14.9
    then the summing row shows (for AllocatedGB, CurrentGB and CurrentFreeGB)
    1,155.000     858     179The thing is that this isn't correct. Firstly; current free isn't equal to allocated - currently used.Looks like it is to me, and I just worked it out in my head.
    Secondly, if I sum all the rows in a spreadsheet, they are
    1171.668 931.897 239.758How do you know the spreadsheet is right and hasn't rounded up/down some figures?

  • Compute sum of two columns - display result in the third column

    Hello,
    I have a report and I want to compute sum of two report columns and display the total in the third column.
    For example: Sample_My_Report
    Col1 Col2 Total (Col1+Col2)
    3 7 10
    can anyone help me out with this issue.
    thanks.

    thanks for replying. One more thing is that
    How can I compute Avg for a particular column in a Master detail report. I need the avg(sal) to be displayed at the end of the report similar to sum(reports total).
    Can you help me out with this issue.
    thanks.

  • Problem with report COMPUTE SUM

    hi @all
    hope sombody can help me
    i have a prob with a report in sql, see script below:
    CLEAR COLUMNS BREAKS COMPUTES;
    COLUMN WORK_TYPE FORMAT a95 HEADING 'Work Type' ENTMAP off
    COLUMN TEXT FORMAT a95 HEADING 'Work Description' ENTMAP off
    COLUMN TOTAL_MAN_MINUTES FORMAT 9999.99 HEADING 'Working Hours' ENTMAP off
    COLUMN TOTAL_MAINT_MAN_MINUTES FORMAT 9999.99 HEADING 'Maintanance Hours' ENTMAP off
    BREAK ON report
    COMPUTE SUM OF TOTAL_MAN_MINUTES TOTAL_MAINT_MAN_MINUTES ON report
    SELECT MWO.WORK_TYPE AS Work_TYpe, WORK_TYPE.TEXT AS Description, SUM(TRUNC(MAINT_ACTION.TOTAL_MAN_MINUTES / 60, 2)) AS Working_Hours, SUM(TRUNC(MAINT_ACTION.TOTAL_MAINT_MAN_MINUTES / 60, 2)) AS Maintanance_Hours
    FROM MAINT_ACTION, MWO, WORK_TYPE
    WHERE MWO.MWO_ID = MAINT_ACTION.originating_mwo_id
    AND MWO.WORK_TYPE = WORK_TYPE.CODE
    AND MWO.AC_SERIAL_NO = 'AS0007'
    AND MAINT_ACTION.START_DATE_TIME_ACT >= '01.04.2010'
    AND MAINT_ACTION.START_DATE_TIME_ACT <= '01.05.2010'
    AND MWO.WORK_TYPE BETWEEN '000' AND '999'
    GROUP BY MWO.WORK_TYPE, WORK_TYPE.TEXT
    ORDER BY MWO.WORK_TYPE, WORK_TYPE.TEXT;
    what i expect is the total working_hours and maintanance_hours per column at the last line from the output, but what i get is only that below
    WORK_TYPE DESCRIPTION WORKING_HOURS MAINTANANCE_HOURS
    041, blablabla, 1,16, 0,58
    105, sülzsülz, 2, 1,5,
    348, bla, 3, 2,33,
    what is my mistake??
    sorry for my bad english
    cu ice
    Edited by: Icebear on May 14, 2010 1:28 AM

    Hi,
    The SQL*Plus command:
    COMPUTE SUM OF TOTAL_MAN_MINUTES TOTAL_MAINT_MAN_MINUTES ON reportmeans "from now on, any time there a result set has is a column called TOTAL_MAN_MINUTES or TOTAL_MAINT_MAN_MINUTES, print the grand total of that column at the end of the report."
    Your result set does not have columns with those names, so the COMPUTE statement does not apply to that query.
    The alias used in the output is what's important; SQL*Plus won't try to find out what columns from the table were used in deriving all the output columns.
    Try using the same column names in both the COMPUTE statement and the query.
    For example:
    COMPUTE SUM OF   Working_Hours   Maintanance_Hours    ON report

  • SQL Plus Bug/Question: 'COMPUTE' command does not work in script.(BUG?!)

    Good Day to ALL!
    I have a script of SQLPlus that creates a report. I have 8/9 numeric columns which are 'SUM'ed up thru 'COMPUTE' command. It works for all BUT 2 columns. If I put these two columns, compute does not take affect. If I remove these two columns ( just cut) 'COMPUTE' works fine!!! These two coulumns use DB Function. But I have other column that also use DB Function. These two columns has some extra additions. Any thing wrong with the script/column defn.
    Thanks - Pradip (Pradip Biswas @Singapore) Could you pl. reply to [email protected]
    Here is bit of script. Sorry about the length of the cut and paste.
    COLUMN OPEN_QTY_BAL           FORMAT 9,99,990          HEADING 'Opening|Qty'           Justify LEFT
    COLUMN OPEN_QTY_VALUE          FORMAT 99,999,990      HEADING 'Opening|S$'           Justify LEFT
    COLUMN PO_RECEIPTS_QTY      FORMAT 99,990          HEADING 'PO Rec|QTY '          Justify LEFT
    COLUMN PO_RECEIPTS_QTY_VALUE     FORMAT 9,999,990      Heading 'PO Rec|S$'           Justify LEFT
    COLUMN MISC_RECEIPTS_QTY     Format 99,990          Heading 'Misc |Qty'          Justify LEFT
    Column MISC_RECEIPTS_QTY_VALUE      Format 9,999,990      Heading 'Misc|S$'          Justify LEFT
    COLUMN WORKORDER_QTY           FORMAT 99,990          HEADING 'WorkOrd|Qty'          Justify LEFT
    COLUMN WorkOrder_QTY_VALUE      Format 9,999,990      HEADING 'WorkOrd|S$'          Justify LEFT
    COLUMN SALES_SHIPMENT_QTY      FOrmat 99,990          Heading 'SalesShip|Qty'          Justify LEFT
    COLUMN SALES_SHIPMENT_QTY_VALUE FOrmat 9,999,990      Heading 'SalesShip|S$'          Justify LEFT
    COLUMN MISC_ISSUE_QTY     Format 99,999          HEADing 'Misc|Qty'          Justify LEFT
    COLUMN MISC_ISSUE_QTY_VALUE Format 9,999,990 heading 'Misc|S$'          Justify LEFT
    COLUMN TRANSFER_QTY          format 99,990          heading 'Transfer|Qty'          Justify LEFT
    COLUMN TRANSFER_QTY_VALUE     format 99,999,990     heading 'Transfer|S$'          Justify LEFT
    COLUMN REVAL_VALUE Format 99,990          Heading 'Reval|S$'          Justify LEFT
    COLUMN ON_HAND_QTY           FORMAT 9,99,990      HEADING 'Closing|Qty'           Justify LEFT
    COLUMN ON_HAND_QTY_VALUE     FORMAT 99,999,999,990      HEADING 'Closing|S$'           Justify LEFT
    REPHEADER on
    REPHEADER left ' GL Period From: &&P_GL_PERIOD_NAME_FROM ' skip left ' GL Period To : &&P_GL_PERIOD_NAME_TO ' skip left ' Inv Org Code : &&P_INV_ORG_CODE ' skip left 'SubInventory Code : &&P_SUBINVENTORY_CODE ' skip 2
    TTITLE left 'H - Inv Inventory Movement Report as at:' TTITLE_DATE RIGHT 'PAGE:' FORMAT 999 SQL.PNO SKIP 2
    BTITLE skip 1 CENTER 'COMPANY CONFIDENTIAL - Printed on ' TTITLE_DATE
    BREAK on REPORT skip 1;
    --rem(1) compute SUM label 'Total' of OPEN_QTY_VALUE PO_RECEIPTS_QTY_VALUE MISC_RECEIPTS_QTY_VALUE WorkOrder_QTY_VALUE SALES_SHIPMENT_QTY_VALUE MISC_ISSUE_QTY_VALUE TRANSFER_QTY_VALUE REVAL_VALUE on report;
    --REM(2) compute SUM label 'Total $S: ' of OPEN_QTY_VALUE REVAL_VALUE on report;
    --REM(3) compute SUM label 'Total $S: ' of OPEN_QTY_VALUE REVAL_VALUE  ON_HAND_QTY_VALUE on report;
    compute SUM label 'Total $S:' of OPEN_QTY_VALUE PO_RECEIPTS_QTY_VALUE MISC_RECEIPTS_QTY_VALUE WorkOrder_QTY_VALUE SALES_SHIPMENT_QTY_VALUE MISC_ISSUE_QTY_VALUE TRANSFER_QTY_VALUE REVAL_VALUE on report;
    WHENEVER SQLERROR EXIT FAILURE
    select
    --     MSI.ORGANIZATION_ID                          ORGANIZATION_ID,
    -- MSI.INVENTORY_ITEM_ID                                   INVENTORY_ITEM_ID,
         MSI.SEGMENT1||'//'||MSI.DESCRIPTION                                   ITEM,
    -- MSI.DESCRIPTION                                             DESCRIPTION,
    All_Item_subinv.SUBINVENTORY_CODE                              SUBINVENTORY,
    MSIV.PRIMARY_UOM_CODE                                        UOM,
         --NVL(MOQ_OPen_BAL.OPEN_QTY_BAL ,0)                               OPEN_QTY_BAL ,
    -- NVL(MOQ_OPen_BAL.OPEN_QTY_BAL,0) * NVL(AVG_ITEM_COST1.ITEM_COST,0)           OPEN_QTY_VALUE,
    (MOQ_OPen_BAL( All_Item_subinv.SUBINVENTORY_CODE,
              MSI.ORGANIZATION_ID,
    MSI.INVENTORY_ITEM_ID,
    '&P_GL_PERIOD_NAME_FROM') )     OPEN_QTY_BAL ,
    (MOQ_OPen_BAL_VAL( All_Item_subinv.SUBINVENTORY_CODE,
              mSI.ORGANIZATION_ID,
    MSI.INVENTORY_ITEM_ID,
    '&P_GL_PERIOD_NAME_FROM')
         )                                             OPEN_QTY_VALUE,
    NVL(AGGREGATED_MTT.PO_RECEIPTS_QTY,0)                              PO_RECEIPTS_QTY,
         NVL(AGGREGATED_MTT.PO_RECEIPTS_QTY_VALUE,0)                          PO_RECEIPTS_QTY_VALUE,
         NVL(AGGREGATED_MTT.MISC_RECEIPTS_QTY,0)                              MISC_RECEIPTS_QTY,
         NVL(AGGREGATED_MTT.MISC_RECEIPTS_QTY_VALUE,0)                          MISC_RECEIPTS_QTY_VALUE,
         NVL(AGGREGATED_MTT.WORKORDER_QTY,0)                              WORKORDER_QTY,
         NVL(AGGREGATED_MTT.WorkOrder_QTY_VALUE,0)                          WorkOrder_QTY_VALUE,
    NVL(AGGREGATED_MTT.SALES_SHIPMENT_QTY,0)                         SALES_SHIPMENT_QTY,
         NVL(AGGREGATED_MTT.SALES_SHIPMENT_QTY_VALUE,0)                         SALES_SHIPMENT_QTY_VALUE,
         NVL(AGGREGATED_MTT.MISC_ISSUE_QTY,0)                              MISC_ISSUE_QTY,
         NVL(AGGREGATED_MTT.MISC_ISSUE_QTY_VALUE,0)                          MISC_ISSUE_QTY_VALUE,
         NVL(AGGREGATED_MTT.TRANSFER_QTY,0)                              TRANSFER_QTY,
         NVL(AGGREGATED_MTT.TRANSFER_QTY_VALUE,0)                         TRANSFER_QTY_VALUE,
         NVL(AGGREGATED_MTT.REVAL_VALUE,0)                              REVAL_VALUE,
              (MOQ_OPen_BAL(All_Item_subinv.SUBINVENTORY_CODE,
              MSI.ORGANIZATION_ID,
    MSI.INVENTORY_ITEM_ID,
    '&P_GL_PERIOD_NAME_FROM')
              +
              nvl(AGGREGATED_MTT.PO_RECEIPTS_QTY,0)      +
              nvl(AGGREGATED_MTT.MISC_RECEIPTS_QTY,0)     +
              nvl(AGGREGATED_MTT.WORKORDER_QTY,0)     +
              nvl(AGGREGATED_MTT.SALES_SHIPMENT_QTY,0)     +
              nvl(AGGREGATED_MTT.MISC_ISSUE_QTY,0)          +
              nvl(AGGREGATED_MTT.TRANSFER_QTY,0)     )                ON_HAND_QTY,
    ((MOQ_OPen_BAL_VAL( All_Item_subinv.SUBINVENTORY_CODE,MSI.ORGANIZATION_ID,MSI.INVENTORY_ITEM_ID,'&P_GL_PERIOD_NAME_FROM'))
    +(nvl( AGGREGATED_MTT.PO_RECEIPTS_QTY_VALUE,0) )     
    +(nvl( AGGREGATED_MTT.MISC_RECEIPTS_QTY_VALUE,0) )
    +(nvl( AGGREGATED_MTT.WorkOrder_QTY_VALUE,0) )
    +(nvl( AGGREGATED_MTT.sALES_SHIPMENT_QTY_VALUE,0) )
    +(nvl( AGGREGATED_MTT.MISC_ISSUE_QTY_VALUE,0) )
    +(nvl( AGGREGATED_MTT.TRANSFER_QTY_VALUE,0) )
    +nvl( AGGREGATED_MTT.REVAL_VALUE,0))                               ON_HAND_QTY_VALUE -- column alias
    FROM
    -- In line View for MSI
    (select distinct MMT.ORGANIZATION_ID, MMT.INVENTORY_ITEM_ID, MMT.SUBINVENTORY_CODE
    From MTL_MATERIAL_TRANSACTIONS      MMT,
    ORG_ORGANIZATION_DEFINITIONS      OOD,
    MTL_ONHAND_QUANTITIES moq
    where
         OOD.organization_code           = '&P_INV_ORG_CODE' --'HS' --'&P_INV_ORG_CODE'
    AND OOD.inventory_enabled_flag = 'Y'
    AND OOD.operating_unit          = fnd_profile.value('ORG_ID') --83 --fnd_profile.value('ORG_ID')
    AND OOD.SET_OF_BOOKS_ID          = fnd_profile.value('GL_SET_OF_BKS_ID') --1 --fnd_profile.value('GL_SET_OF_BKS_ID')
    AND     MMT.ORGANIZATION_ID          = OOD.organization_id
    AND MMT.SUBINVENTORY_CODE          = NVL('&P_SUBINVENTORY_CODE', MMT.SUBINVENTORY_CODE)
    and MMT.ORGANIZATION_ID      = MOQ.ORGANIZATION_ID -- to eliminate consigend items:2007Jan04:PKB
    and MMT.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID --,,
    and MMT.SUBINVENTORY_CODE = MOQ.SUBINVENTORY_CODE --,,
    UNION
    Select distinct      MOQ.ORGANIZATION_ID,      MOQ.INVENTORY_ITEM_ID,     MOQ.SUBINVENTORY_CODE
    from      MTL_ONHAND_QUANTITIES                MOQ,
         ORG_ORGANIZATION_DEFINITIONS           OOD2
    WHERE
         OOD2.organization_code           = '&P_INV_ORG_CODE' --'HS' --'&P_INV_ORG_CODE'
    AND OOD2.inventory_enabled_flag      = 'Y'
    AND OOD2.operating_unit          = fnd_profile.value('ORG_ID') --83 --fnd_profile.value('ORG_ID')
    AND OOD2.SET_OF_BOOKS_ID          = fnd_profile.value('GL_SET_OF_BKS_ID') --1 --fnd_profile.value('GL_SET_OF_BKS_ID')
    AND moq.ORGANIZATION_ID          = OOD2.organization_id
    AND moq.SUBINVENTORY_CODE          = NVL('&P_SUBINVENTORY_CODE', moq.SUBINVENTORY_CODE)
    ) ALL_Item_SUBInv,
    MTL_SYSTEM_ITEMS_B MSI,
    Mtl_System_Items_Vl MSIV,
    (SELECT
         MMT.ORGANIZATION_ID ORGANIZATION_ID,
    MMT.INVENTORY_ITEM_ID          INVENTORY_ITEM_ID,
    MMT.SUBINVENTORY_CODE          SUBINVENTORY_CODE,
    -- PO RECEIPTS.
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Purchase order')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('PO Receipt','PO Rcpt Adjust','Return to Vendor')
    THEN
                   --MMT.TRANSACTION_QUANTITY
                   mmt.primary_quantity
    ELSE 0
    END
    ELSE 0
    END ) PO_RECEIPTS_QTY,
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Purchase order')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('PO Receipt','PO Rcpt Adjust','Return to Vendor')
    THEN
                   NVL(MMT.ACTUAL_COST,0)* nvl(mmt.primary_quantity,0)
                   MMT.TRANSACTION_COST * NVL(AVG_ITEM_COST.ITEM_COST,0)
    ELSE 0
    END
    ELSE 0
    END ) PO_RECEIPTS_QTY_VALUE,
    -- MISC RECEIPTS.
    SUM( CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Account','Inventory')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Account receipt','Miscellaneous receipt')
    THEN
                   --MMT.TRANSACTION_QUANTITY
                   mmt.primary_quantity
    ELSE 0
    END
    ELSE 0
    END ) MISC_RECEIPTS_QTY,
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Account', 'Inventory')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Account receipt','Miscellaneous receipt')
    THEN
                   NVL(MMT.ACTUAL_COST,0) * nvl(mmt.primary_quantity,0)
                        MMT.TRANSACTION_COST NVL(AVG_ITEM_COST.ITEM_COST,0)
    ELSE 0
    END
    ELSE 0
    END ) MISC_RECEIPTS_QTY_VALUE,
    -- WorkOrder Qty and S$
    SUM( CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Job or Schedule')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('WIP Assembly Return','WIP Assy Completion','WIP component issue','WIP Component Return')
    THEN
                   --MMT.TRANSACTION_QUANTITY
                   mmt.primary_quantity
    ELSE 0
    END
    ELSE 0
    END ) WORKORDER_QTY,
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Job or Schedule')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('WIP Assembly Return','WIP Assy Completion','WIP component issue','WIP Component Return')
    THEN
                   NVL(MMT.ACTUAL_COST,0) * nvl(mmt.primary_quantity,0)
                        MMT.TRANSACTION_COST NVL(AVG_ITEM_COST.ITEM_COST,0)
    ELSE 0
    END
    ELSE 0
    END ) WorkOrder_QTY_VALUE,
    -- Sales Shipment
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ( 'Sales order','RMA')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Sales order issue','Sales Order Pick','RMA Return','RMA Receipt')
    THEN
                   --MMT.TRANSACTION_QUANTITY
                   mmt.primary_quantity
    ELSE 0
    END
    ELSE 0
    END ) SALES_SHIPMENT_QTY,
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ( 'Sales order','RMA')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Sales order issue','Sales Order Pick','RMA Return','RMA Receipt')
    THEN
                   NVL(MMT.ACTUAL_COST,0) * nvl(mmt.primary_quantity,0)
                   MMT.TRANSACTION_COST NVL(AVG_ITEM_COST.ITEM_COST,0)
    ELSE 0
    END
    ELSE 0
    END ) SALES_SHIPMENT_QTY_VALUE,
    -- MISC ISSUE
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Inventory','Account' )
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Miscellaneous issue','Account issue')
    THEN
                   --MMT.TRANSACTION_QUANTITY
                   mmt.primary_quantity
    ELSE 0
    END
    ELSE 0
    END ) MISC_ISSUE_QTY,
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ('Inventory','Account' )
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Miscellaneous issue','Account issue')
    THEN
                   NVL(MMT.ACTUAL_COST,0) * nvl(mmt.primary_quantity,0)
                   MMT.TRANSACTION_COST NVL(AVG_ITEM_COST.ITEM_COST,0)
    ELSE 0
    END
    ELSE 0
    END ) MISC_ISSUE_QTY_VALUE,
    -- Transfers
    SUM( CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ( 'Inventory' )
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Subinventory Transfer')
    THEN
                   --MMT.TRANSACTION_QUANTITY
                   mmt.primary_quantity
    ELSE 0
    END
    ELSE 0
    END ) TRANSFER_QTY,
    SUM( CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ( 'Inventory')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Subinventory Transfer')
    THEN      NVL(MMT.ACTUAL_COST,0) * nvl(mmt.primary_quantity,0)
                   MMT.TRANSACTION_COST NVL(AVG_ITEM_COST.ITEM_COST,0)
    ELSE 0
    END
    ELSE 0
    END ) TRANSFER_QTY_VALUE,
    -- Adjustment to Cost (Revaluation)
    SUM(CASE
         WHEN MTST.TRANSACTION_SOURCE_TYPE_NAME in
    ( 'Standard cost update','Job or Schedule')
         THEN
              CASE
              WHEN MTT.TRANSACTION_TYPE_NAME in
    ('Standard cost update','WIP cost update')
    THEN
                   --2007JAN03:PKB MMT.TRANSACTION_COST
    MMT.TRANSACTION_COST* MMT.QUANTITY_ADJUSTED
    ELSE 0
    END
    ELSE 0
    END ) REVAL_VALUE
         FROM
         MTL_MATERIAL_TRANSACTIONS                MMT,
         --GL_PERIODS                          GP,
         MTL_TRANSACTION_TYPES                MTT,
         MTL_TXN_SOURCE_TYPES                    MTST,
    ORG_ORGANIZATION_DEFINITIONS                OOD
    WHERE     
    OOD.organization_code           = '&P_INV_ORG_CODE' --'HS' --'&P_INV_ORG_CODE'
    AND OOD.inventory_enabled_flag = 'Y'
    AND OOD.operating_unit          = fnd_profile.value('ORG_ID') --83 --fnd_profile.value('ORG_ID')
    AND OOD.SET_OF_BOOKS_ID          = fnd_profile.value('GL_SET_OF_BKS_ID') --1 --fnd_profile.value('GL_SET_OF_BKS_ID')
    AND     MMT.ORGANIZATION_ID          = OOD.organization_id
    AND MMT.SUBINVENTORY_CODE          = NVL('&P_SUBINVENTORY_CODE', MMT.SUBINVENTORY_CODE)
    -- AND GP.PERIOD_SET_NAME          = 'HF-ACCTG-CAL' -- Hardcoded PKB
    AND
         (     (EXISTS
         ( select GP.Period_name
    FROM GL_PERIODS GP
    where TO_DATE(TO_CHAR(MMT.TRANSACTION_DATE,'DD-MM-YYYY'),'DD-MM-YYYY')
                   >= TO_DATE(TO_CHAR(GP.START_DATE,'DD-MM-YYYY'),'DD-MM-YYYY') --Between GP.START_DATE and GP.END_DATE
         AND GP.PERIOD_NAME      = '&P_GL_PERIOD_NAME_FROM'
              and GP.PERIOD_SET_NAME          = 'HF-ACCTG-CAL'
    AND NVL('&P_GL_PERIOD_NAME_FROM','ALL')      != 'ALL'
    OR (NVL('&P_GL_PERIOD_NAME_FROM' ,'ALL')               = 'ALL')
    AND
         (     (EXISTS
         ( select GP.Period_name
    FROM GL_PERIODS GP
    where TO_DATE(TO_CHAR(MMT.TRANSACTION_DATE,'DD-MM-YYYY'),'DD-MM-YYYY')
                   <= TO_DATE(TO_CHAR(GP.END_DATE,'DD-MM-YYYY'),'DD-MM-YYYY')
         AND GP.PERIOD_NAME      = '&P_GL_PERIOD_NAME_TO'
              and GP.PERIOD_SET_NAME          = 'HF-ACCTG-CAL'
    AND NVL('&P_GL_PERIOD_NAME_TO','ALL')      != 'ALL'
    OR (NVL('&P_GL_PERIOD_NAME_TO','ALL')               = 'ALL')
    AND MMT.TRANSACTION_TYPE_ID          = MTT.TRANSACTION_TYPE_ID
    AND MMT.TRANSACTION_SOURCE_TYPE_ID          = MTST.TRANSACTION_SOURCE_TYPE_ID
    group by
         MMT.ORGANIZATION_ID,
    MMT.INVENTORY_ITEM_ID,
    MMT.SUBINVENTORY_CODE
    )                    AGGREGATED_MTT,
    -- Inline Table for AVG_ITEM_COSTs 2nd time,
    (SELECT
         CIC.ORGANIZATION_ID     ORGANIZATION_ID,
    CIC.INVENTORY_ITEM_ID INVENTORY_ITEM_ID,
    CIC.COST_TYPE_ID COST_TYPE_ID,
    CCT.COST_TYPE     COST_TYPE,
    NVL(CIC.ITEM_COST ,0) ITEM_COST
    FROM
         CST_ITEM_COSTS           CIC,
         CST_COST_TYPES           ccT,
    ORG_ORGANIZATION_DEFINITIONS                OOD1
    WHERE
         CCT.COST_TYPE_ID           = CIC.COST_TYPE_ID
         /*AND (
         (CCT.COST_TYPE          = 'Average' and '&P_INV_ORG_CODE' = 'HS')
              OR
    (CCT.COST_TYPE          = 'Frozen' and '&P_INV_ORG_CODE' = 'HL')
    AND CCT.COST_TYPE_ID =
              ( select      m.primary_cost_method
              from      mtl_parameters m
    where      m.organization_id      = OOD1.ORGANIZATION_ID
         and OOD1.organization_code      = '&P_INV_ORG_CODE' --'HS' --'&P_INV_ORG_CODE'
         AND OOD1.inventory_enabled_flag = 'Y'
         AND OOD1.operating_unit          = fnd_profile.value('ORG_ID') 83 --fnd_profile.value('ORG_ID')
         AND OOD1.SET_OF_BOOKS_ID     = fnd_profile.value('GL_SET_OF_BKS_ID') 1 --fnd_profile.value('GL_SET_OF_BKS_ID')
         AND cic.ORGANIZATION_ID          = OOD1.organization_id
         )                               AVG_ITEM_COST1
    WHERE
    AGGREGATED_MTT.ORGANIZATION_ID(+)          = All_Item_subinv.ORGANIZATION_ID
    AND AGGREGATED_MTT.INVENTORY_ITEM_ID(+) = All_Item_subinv.INVENTORY_ITEM_ID
    AND AGGREGATED_MTT.subinventory_code(+)     = All_Item_subinv.subinventory_code
    AND All_Item_subinv.ORGANIZATION_ID          = MSI.ORGANIZATION_ID
    AND ALL_Item_SUBInv.INVENTORY_ITEM_ID          = MSI.INVENTORY_ITEM_ID
    AND AVG_ITEM_COST1.ORGANIZATION_ID(+)     = MSI.ORGANIZATION_ID
    AND AVG_ITEM_COST1.INVENTORY_ITEM_ID(+)      = MSI.INVENTORY_ITEM_ID
    and msi.ROWID                         = MSIV.ROW_ID
    and msi.ORGANIZATION_ID                    = fnd_profile.value('ORG_ID') --83 --fnd_profile.value('ORG_ID')
    and sysdate between NVL(msi.start_date_active,sysdate -1 )
    and NVL(msi.end_date_active,sysdate+1)
    Order BY
         MSI.SEGMENT1,
    MSI.DESCRIPTION     ,
    All_Item_subinv.SUBINVENTORY_CODE
    /

    Hi Barry and All: This indeed is a bug in SQLPLUS ! Version 9.2.0.1.0 as well.
    Thanks for asking the version no of SQLLPLUs. I was working thru Oracle Apps 11i.10 (concurrent program). So I did not get any message from SQLPLUS.
    I tested independently in SQLPLUS and got the message! Thanks Oracle!!!
    The Bug is in the name of COLUMN NAME or ALIAS Name. I renamed the columns from ON_HAND_QTY and ON_HAND_VALUE to CLOSE_QTY and CLOSE_QTY_VALUE. It worked!! The string 'ON' in the column/alias name is taken as 'ON' keyword/clause for 'compute' statement for SQLPLUS.
    Here is the message from SQLPLUS
    " SP2-0084: COMPUTE ON keyword specified already"
    See these two line and compare
    --compute SUM label 'Total $S: ' of SALARY ON_SALARY  on report;
    compute SUM label 'Total $S: ' of SALARY on report;
    Thanks - Pradip
    Here is the sample code to simulate. (not Big :))
    WHENEVER SQLERROR EXIT FAILURE
    CLEAR computes
    CLEAR BREAKS
    clear column
    TTITLE OFF
    BTITLE OFF
    set verify off
    set feedback off
    set echo off
    set heading off
    set termout off
    set linesize 203
    set pagesize 30
    set termout on
    SET UNDERLINE =
    set heading on
    COLUMN SALARY               FORMAT 9,999,990      Heading 'SALARY'           
    COLUMN ON_SALARY          format 9,999,990 Heading 'ON Salary'
    column ENAME format a20 heading 'NAME'
    COLUMN EMPNO Format 99999 HEADING 'EMPNO'
    BREAK on REPORT skip 3;
    --compute SUM label 'Total $S: ' of SALARY ON_SALARY  on report;
    compute SUM label 'Total $S: ' of SALARY on report;
    WHENEVER SQLERROR EXIT FAILURE
    select empno, ename, sal SALARY, sal ON_SALARY from scott.emp;

  • Sql developer with compute function/ add total to column.

    Hello experts i've been strugglin for a couple of hours on this. and im not sure if this is the forum i should be posting this but i could not found a forum directly related to sql developer.
    I would like to use the compute function in sql developer but it does not appear to work can someone please point me in the right direction.
    i followed this documentation
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch6.htm
    but it does not seem to do the trick. I basically just would like to add a total at the end of my query ?...
    can someone throw me a bone on this one.
    Miguel

    column DUMMY NOPRINT
    compute sum of aamt on DUMMY
    break on  dummy
      select a_fa_idoc, b_fr_idoc, a_amt, b_amt, (a_amt-b_amt)
      from
       (SELECT  a.fa_idoc a_fa_idoc,  SUM(a.amt) a_amt from fwrinva  a group by a.fa_idoc) fwarinva_summary
      inner join
       (SELECT  b.fr_idoc b_fr_idoc,   sum(b.amt) b_amt from  fwrinvc b group by b.fr_idoc) fwrinvc_summary
       on( fwarinva_summary.a_fa_idoc = fwrinvc_summary.b_fr_idoc)
      where (a_amt - b_amt) = 0;here is my query but it does not put a total on the end?

  • COMPUTE function: How to get subtotals and GRAND total together?

    I am wrtiting a report using SQL and SQL*Plus to get subtotals and a grand total. The COMPUTE function allows me to COMPUTE SUM on a group, but it only gives me subtotals. I'm interested in getting a report with the SUBTOTALS and a final GRAND TOTAL. Can this be done using SQL*Plus?
    Here is my current code that gives me subtotals:
    COMPUTE SUM LABEL subtotal OF sal ON deptno
    SELECT ename, sal, deptno
    FROM emp
    ORDER BY deptno;
    ENAME             SAL     DEPTNO
    CLARK            2450         10
    VOLLMAN          5000
    MILLER           1300
                     8750 subtotal
    SMITH             800         20
    ADAMS            1100
    FORD             3000
    SCOTT            3000
    JONES            2975
                    10875 subtotal
    ALLEN            1600         30
    BLAKE            2850
    MARTIN           1250
    JAMES             950
    TURNER           1500
    WARD             1250
                     9400 subtotalHere is the code to give one grand total:
    Column DUMMY NOPRINT
    COMPUTE SUM OF sal ON DUMMY
    BREAK ON DUMMY
    SELECT NULL DUMMY, ename, sal, deptno
    FROM emp
    ORDER BY deptno;
    ENAME             SAL     DEPTNO
    CLARK            2450              10
    VOLLMAN          5000          10
    MILLER           1300          10
    SMITH             800              20
    ADAMS            1100          20
    FORD             3000          20
    SCOTT            3000          20
    JONES            2975          20
    ALLEN            1600              30
    BLAKE            2850          30
    MARTIN           1250          30
    JAMES             950          30
    TURNER           1500          30
    WARD             1250          30
                    29025
    How can I combine both on one report?

    Massimo Ruocchio wrote:
    Do you like this?I believe OP is looking for both department totals and grand total. Frank already showed how to do it in SQL*Plus. To do it in SQL:
    SELECT  CASE GROUPING_ID(real_deptno,real_ename)
              WHEN 0 then real_ename
              WHEN 1 then 'Department ' || real_deptno || ' total'
              ELSE 'All department total'
            END ename,
            SUM(sal),
            deptno
      FROM  (
             SELECT  deptno real_deptno,
                     ename real_ename,
                     sal,
                     CASE ROW_NUMBER() OVER(PARTITION BY deptno order by ename) WHEN 1 THEN deptno end deptno
               FROM  emp
      GROUP BY GROUPING SETS((),real_deptno,(real_deptno,deptno,real_ename))
      ORDER BY real_deptno nulls last,
               real_ename nulls last
    ENAME                  SUM(SAL)     DEPTNO
    CLARK                      2450         10
    KING                       5000
    MILLER                     1300
    Department 10 total        8750
    ADAMS                      1100         20
    FORD                       3000
    JONES                      2975
    SCOTT                      3000
    SMITH                       800
    Department 20 total       10875
    ALLEN                      1600         30
    ENAME                  SUM(SAL)     DEPTNO
    BLAKE                      2850
    JAMES                       950
    MARTIN                     1250
    TURNER                     1500
    WARD                       1250
    Department 30 total        9400
    All department total      29025
    18 rows selected.
    SQL> SY.

  • Sum in sql

    I have two tables in oracle 10g
    id............code..........name
    1..............10...........local1
    2..............20...........local2
    3..............30...........local3
    id.............local..............created
    1...............1..............12.11.2010
    2...............2..............16.11.2010
    3...............3..............12.11.2010
    4...............6..............08.10.2010
    select s.name,s.code,
    TO_CHAR(p.created,'MM') month,
    count(p.id)
    from local s,made p
    where p.local = s.id
    GROUP BY s.name,s.code,TO_CHAR(p.created,'MM')
    ORDER BY s.code
    After I get my query:
    how much each month something local made
    How do I get for each local total of all months.
    local1..............10..............1..................57
    ......................................2..................63
    ......................................3..................23
    sum...................................................XXX
    local2..............20..............1.................34
    ......................................2.................72
    ......................................3.................68
    sum..................................................XXX
    and so on.
    thanks

    BREAK ON name
    COMPUTE SUM OF amount ON name
    select s.name,s.code,
    TO_CHAR(p.created,'MM') month,
    count(p.id) amount
    from local s,made p
    where p.local = s.id
    GROUP BY s.name,s.code,TO_CHAR(p.created,'MM')
    ORDER BY s.code;

  • Display a Custom Sum that will Ignore Certain values

    In addition to the sum that I am computing on Current Total Column in SQL Plus, I also want to do a Custom Sum on Current Total Column that will ignore certain values of the Current Total column, but displays at the same frequency as the break group. How can I do it in SQL Plus?

    Hi!
    I think you can use DECODE or user-defined function to create an artificial output column in your query ignoring certain values of the Current Total column and then just compute sum on it as you did on Current Total.
    Regards,
    Andrew Velitchko
    BrainBench MVP for Developer/2000
    http://www.brainbench.com

  • Tweak for sql query - help needed for smalll change

    Hi.
    I am trying to run a script that checks for used space on all tablespaces and returns the results.
    So far so good:
    set lines 200 pages 2000
    col tablespace_name heading 'Tablespace' format a30 truncate
    col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
    col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
    col used_space_mb heading 'MB|Used' format 9G999G999D99
    col free_space_mb heading 'MB|Free Till Max' like used_space_mb
    col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
    col pct_used heading '%|Used' format 999D99
    col pct_free heading '%|Free' like pct_used
    break on report
    compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
    select
    alloc.tablespace_name,
    (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
    free.free_space_mb free_space_ext_mb,
    ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
    FROM (SELECT tablespace_name,
    ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
    ROUND(SUM(bytes)/1048576) total_allocspace_mb
    FROM dba_data_files
    WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    GROUP BY tablespace_name) alloc,
    (SELECT tablespace_name,
    SUM(bytes)/1048576 free_space_mb
    FROM dba_free_space
    WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    GROUP BY tablespace_name) free
    WHERE alloc.tablespace_name = free.tablespace_name (+)
    ORDER BY pct_used DESC
    The above returns something like this:
    MB MB % %
    Tablespace Used Free Till Ext Used Free
    APPS_TS_ARCHIVE 1,993.13 54.88 97.32 2.68
    APPS_TS_TX_IDX 14,756.13 1,086.88 91.37 8.63
    APPS_TS_TX_DATA 20,525.75 594.25 80.18 19.82
    APPS_TS_MEDIA 6,092.00 180.00 74.37 25.63
    APPS_TS_INTERFACE 13,177.63 366.38 71.49 28.51
    The above works fine, but I would like to further change the query so that only those tablespaces with free space less than 5% (or used space more than 95%) are returned.
    I have been working on this all morning and wanted to open it up to the masters!
    I have tried using WHERE pct_used > 95 but to no avail.
    Any advice would be appreciated.
    Many thanks.
    10.2.0.4
    Linux Red Hat 4.

    Thanks for that.
    What is confusing is that the below query works for every other (about 10 others) database but not this one (?)
    SQL> set lines 200 pages 2000
    SQL>
    SQL> col tablespace_name heading 'Tablespace' format a30 truncate
    SQL> col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
    SQL> col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
    SQL> col used_space_mb heading 'MB|Used' format 9G999G999D99
    SQL> col free_space_mb heading 'MB|Free Till Max' like used_space_mb
    SQL> col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
    SQL> col pct_used heading '%|Used' format 999D99
    SQL> col pct_free heading '%|Free' like pct_used
    SQL>
    SQL> break on report
    SQL> compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
    SQL>
    SQL> select /*+ALL_ROWS */
    2 alloc.tablespace_name,
    3 alloc.total_maxspace_mb,
    4 alloc.total_allocspace_mb,
    5 (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
    6 free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb) free_space_mb,
    7 free.free_space_mb free_space_ext_mb,
    8 ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    9 ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
    10 FROM (SELECT tablespace_name,
    11 ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
    12 ROUND(SUM(bytes)/1048576) total_allocspace_mb
    13 FROM dba_data_files
    14 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    15 GROUP BY tablespace_name) alloc,
    16 (SELECT tablespace_name,
    17 SUM(bytes)/1048576 free_space_mb
    18 FROM dba_free_space
    19 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    20 GROUP BY tablespace_name) free
    21 WHERE alloc.tablespace_name = free.tablespace_name (+)
    22 ORDER BY pct_used DESC
    23 /
    ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    ERROR at line 8:
    ORA-01476: divisor is equal to zero

  • How to add numbers in XML?567- 5+6+7=18?

    I have a requirement in check printing to print the check no at the bottom of the check.
    1.     Compute sum of all the digits in the check number and divide it by 9.
    E.g.:
    1.     0+0+7+0+0+5+7+9 = 28 (SUM)
    2.     28 / 9 = 3 (with remainder 1)
    3.2.     Compute the difference between 9 and the remainder in step 2. This number is the check digit (Modulus 9).
    E.g.:
    1.     9 – 1 = 8
    2.     8 is the check digit.
    If the remainder in Step2=0, then the check digit is 9
    So I will display 007005798
    In XML or XSL , How can I do this?
    Question: Is there any built in SQL function available to compute the sum of individuals of a number?For eg 567-> 5+6+7=18
    If I am ending up wrinting a function for the above how can I call that in RTF?
    thanks
    prasanna

    Srini
    Can you please help me out..The xml formula works for hardcoded values but not for the actual tag values.
    1) I am not finding space to copy the following into the form field:\
    You gave:
    <?9-((substring(555555555,1,1)+ substring (555555555,2,1) + substring (555555555,3,1) + substring (555555555,4,1) + substring (555555555,5,1) + substring (555555555,6,1) + substring (555555555,7,1) + substring (555555555,8,1) + substring (555555555,9,1)) mod 9)?>
    I remodified for my situation:
    <?9-((substring(../PaymentNumber/CheckNumber,1,1)+ substring (../PaymentNumber/CheckNumber,2,1) +
    substring (../PaymentNumber/CheckNumber,3,1) + substring (../PaymentNumber/CheckNumber,4,1) +
    substring (../PaymentNumber/CheckNumber,5,1) + substring (../PaymentNumber/CheckNumber,6,1) +
    substring (../PaymentNumber/CheckNumber,7,1) + substring (../PaymentNumber/CheckNumber,8,1) +
    substring (../PaymentNumber/CheckNumber,9,1)) mod 9)?>
    But the above dont fit into the form field.How to take care of this?
    thanks
    prasanna

  • Java Progrramming HELP, Needed Urgently, T hanks

    hey guys,
    I have this lab I need to be done tomorrow, its been weeks lol of thinking and figuring things out can someone make it work ? Pleaseeeee !
    I feel like going out and yelling for help lol I have been trying to figure this out for weeks now.
    I am pasting my Lab and My Codes I did so far, And Please I really need this done today at any rate, all help would be kindly appreciated.
    A Java program is required that will produce a number of reports based on the data from the Product file. This file contains the product name, cost, quantity and UPC. The file name must be input. Valid data from the file will be loaded into an array.
    A menu will provide the following options: (Note there are changes from previous assignment.)
    1     Display of all valid product information including extended price and GST including totals sorted by name.
    2     Display of all invalid records sorted by name.
    3     Search and display a certain product by name.
    4     Sort by UPC and use a binary search and display a certain product by UPC. (valid records)
    9 Exit.
    Processing requirements:
    Input the data from a file and load the records into an object array. Use this object array to produce the above reports.
    Code a class definition exactly as given in the following UML.
    (For specific students: you may code the UPC as an integer but if not numeric throw an exception that is handled in main. Document your choice in your submission).
    Product
    ? Name : String
    ? UPC : String
    ? Cost : Real
    ? Quantity : Integer
    + Product (Name : String, UPC : String, Cost : Real, Quantity : Integer)
    + Calculate Extended Cost() : Real
    + Calculate GST(): Real
    Input Record:
    Product name: String
    UPC: String
    Cost: real
    Quantity: integer
    Output Reports
    1. Display of all product information including extended cost and GST including totals of these 3 fields.
    Following is a sample of the output required:
    ************************ Product Cost REPORT ****************************
    Product                    Cost Quantity Extended Cost     GST     Total Cost
    Diamond Necklace 12345678901x 54,321.99 188 10,212,534.12 510,626.71 10,723,160.83
    Tissues 98989898989x 1.99 2 3.98      0.20     4.18
    TOTALS                         10,212,538.10 510,626.91 10,723,165.01
    2. Display of all invalid records and the count.
    Following is a sample of the output required:
    Invalid UPC Records = 1
    Count Record
    1          Tiara Diamond, 12345678901x, 36020.00, 2
    3. Search and display a certain product by name. Display appropriate message if not found.
    Following is a sample of the output required:
    Enter product name: CrownJewels
    CrownJewels 99999999991x     100,000.00 1 100,000.00 5,000.00 $105,000.00
    6. Display the product information sorted by name
    Following is a sample of the output required:
    ************************ Product Cost REPORT ****************************
    Product                    Cost Quantity Extended Cost     GST     Total Cost
    CrownJewels 99999999991x 100,000.00 1 100,000.00 5,000.00 $105,000.00
    Diamond Necklace 12345678901x 54,321.99 188 10,212,534.12 510,626.71 $10,723,160.83
    Pearls      88888888881x 10,000.00 1 10,000.00 500.00 $10,500.00
    RubyRing      77777777771x 10,000.00 1 10,000.00 500.00 $10,500.00
    Tissues      98989898989x 1.99 2 3.98 0.20     $4.18
    TOTALS          (complete these values)           xxx           xxx      xxx
    Java coding requirements for this assignment
    Main methods required
    1.     Load array with all records. Display exception messages only for records that have invalid data in any of the fields. Return array of valid records and logical size.
    2.     Validate the UPC. Display each report when requested from the menu.
    3.     Justify the data in the columns. Right justify numeric fields; left justify the alpha fields.
    4.     A method for each report required in the menu.
    Class methods
    5.     Use the object method for the extended cost.
    6.     Use the object method for the GST.
    You may use additional methods in the main program but do not add any methods in the class definition.
    Use DecimalFormat for rounding.
    Create an array to hold the objects. Assume that we only need to process a file of a maximum of 500 records but the file may be larger than 500 records.
    A Universal Product Code consists of 12 digits. The first digit (from the left) is the UPC type. The next five digits are the Manufacturer code. The next five digits are the product code which is assigned by the manufacturer. The final digit is the check digit. A person can determine the check digit of a Universal Product Code by doing the following:
    Step 1: Sum all of the digits in the odd positions together.
    0+4+0+1+5+9 = 19
    Step 2: Multiply the sum from Step 1 by 3.
    3 * 19 = 57
    Step 3: Sum all of the digits in the even positions together.
    6+2+0+1+8 = 17
    Step 4: Sum together the results from Step 2 and Step 3.
    17 + 57 = 74
    Step 5: Subtract the sum from the next highest multiple of 10.
    80 - 74 = 6 [check digit]
    TEST DATA:
    Step 1: Create 5 or MORE additional records that will test all conditions. Include these in your documentation. Identify what field is tested in your test data. (Example: error in each field of the record, rounding up, rounding down, valid UPC, invalid UPC, formatting of report, file too large
    Step 2: Use the file attached.
    GODDDDDDDDDDDDDD lol pasting it made me go crazy,
    these are my codes so far, HOwever the problem is ONLY DISPLAY MENU SHOWS, nothing else even though i have enough codes that it can show something,
    My codes are as follows:
    I am working on Eclipse.
    import java.util.Arrays;
    import java.util.Scanner;
    import java.io.*;
    import java.util.*;
    import java.io.IOException;
    * Name : Sana Ghani
    * Date : July 10
    public class lab56
         public static Scanner file;
         public static Scanner parse;
         public static Scanner input = new Scanner(System.in);
         public static Scanner searchInput = new Scanner(System.in);
         public static void main(String[] args) throws Exception
              Product1[] validProduct = new Product1[500];
              int logicalSize = 0;
              int menuChoice=0;
              String FileName = getFileName();
              displayMenu();
              switch(menuChoice)
              case 1:
                   displayAllValidRecords(validProduct, logicalSize);
                   try
                   // Open an output stream
                   OutputStream fout = new FileOutputStream ("myfile.txt");
                   // Print a line of text
                   new PrintStream(fout).println ("hello world!");
                   // Close our output stream
                   fout.close();          
                   // Catches any error conditions
                   catch (IOException e)
                        System.err.println ("Unable to write to file");
                        System.exit(-1);
                   break;
              case 2:
                   break;
              case 3:
                   binarySearchByName( validProduct,logicalSize);
                   break;
              case 4:
                   break;
              case 5:
                   break;
              menuChoice = displayMenu();
         public static void display(Product1[]validProduct, int logicalSize)throws Exception
              String Product, UPC;
              double Cost;
              int Quantity;
              for(int index =0; index<logicalSize; index++)
                   Product = validProduct[index].GetName();
                   UPC = validProduct[index].GetUPC();
                   Cost=validProduct[index].GetCost();
                   Quantity=validProduct[index].GetQuantity();
                   System.out.println(Product+"\t\t"+UPC+"\t\t"+Cost+"\t\t"+Quantity);
         public static String getFileName()
              String fileName;
              Scanner input = new Scanner(System.in);
              System.out.print("Please enter a file name: ");
              fileName = input.next();
              return fileName;
         public static int displayMenu()
              int menuChoice;
              boolean validFlag = false;
              do
                   System.out.println("\n\n*************************************");
                   System.out.println(" Product Display Menu ");
                   System.out.println("*************************************");
                   System.out.println("(1)Display All Records");
                   System.out.println("(2)Display All Invalid Records");
                   System.out.println("(3)Search by Product Name");
                   System.out.println("(4)Sort by Product Name");
                   System.out.println("(5)Exit");
                   System.out.println("*************************************");
                   System.out.print("Enter your choice(1-5): ");
                   menuChoice = input.nextInt();
                   if ((menuChoice >= 1) && (menuChoice <= 5))
                        validFlag = true;
                   if (!validFlag)
                        System.out.println("You have chosen " + menuChoice + ", " + menuChoice +
                        " is not valid. Please try again");
              }while(!validFlag);
              return menuChoice;
         public static String loadArray(Product1 [] ValidProduct, String fileName)throws Exception
              int logicalSize=0;//will always have to declare
              String record;//will always have to declare
              String Product, UPC;//variable names from
              double Quantity;
              double Cost;
              Scanner file = new Scanner(new File(fileName));//open
              record = file.nextLine();//read a line
              record = file.nextLine();//read a line
              for(int index = 0; index < ValidProduct.length && file.hasNext(); index++)//check to see if the file has data
                   record = file.nextLine();
                   parse = new Scanner(record).useDelimiter(",");
                   String Name = parse.next();
                   UPC = parse.next();
                   Cost = parse.nextDouble();
                   Quantity=parse.nextDouble();
                   ValidProduct[index] = new Product1 ( Name, UPC, Cost, (int) Quantity);
    //               create the object-- call the constructor and pass info
                   logicalSize++;
              return logicalSize+".txt";
         public static double roundDouble(double value, int position)
              java.math.BigDecimal bd = new java.math.BigDecimal(value);
              bd = bd.setScale(position,java.math.BigDecimal.ROUND_UP);
              return bd.doubleValue();
         * This method will print report about valid records
         public static void displayAllRecords( Product1[]valid, int ValidProduct,
                   Product1[] invalid, int InvalidProduct)
    //          Print valid records
              displayAllValidRecords(valid, ValidProduct);
    //          Print invalid UPC records
              displayAllValidRecords(invalid, InvalidProduct);
         public static void displayOneRecord(Product1[]valid, int index)
              double extendedCost, GST, SumofGST = 0, // Total Extended Cost
              totalCost, SumOfTotalCost = 0; // Total Extended Cost + GST
    //          Print title
              System.out.println(leftJustify("Product", 50) +
                        leftJustify("UPC", 15) +
                        rightJustify("Cost", 10) +
                        rightJustify("Quantity", 5) +
                        rightJustify("Extended Cost", 15) +
                        rightJustify("GST", 5) +
                        rightJustify("Total Cost", 13));
              extendedCost = valid[index].CalculateExtendedCost();
              extendedCost = roundDouble(extendedCost, 2);
              GST = valid[index].CalculateGST();
              GST = roundDouble(GST, 2);
              totalCost = extendedCost + GST;
              totalCost = roundDouble(totalCost, 2);
    //          justify method ensures all values are of the same size
              System.out.println(//leftJustify(i+"",3) + ": " +
                        leftJustify(valid[index].GetName(), 50) +
                        leftJustify(valid[index].GetUPC(), 15) +
                        rightJustify(valid[index].GetCost()+"", 10) +
                        rightJustify(valid[index].GetQuantity()+"", 5) +
                        rightJustify(extendedCost+"", 10) +
                        rightJustify(GST+"", 10) +
                        rightJustify(totalCost+"", 10));
         * This method will print report about valid records
         public static void displayAllValidRecords( Product1[]valid, int validCounter)
              double extendedCost, sumOfExtendedCost = 0, // Total Extended Cost
              GST, sumOfGST = 0, // Total GST
              totalCost, sumOfTotalCost = 0; // Total Extended Cost + GST
              System.out.println("************************ XYZ Product " +
                        "Cost REPORT ****************************" +
    //          Print title
              System.out.println(leftJustify("Product", 50) +
                        leftJustify("UPC", 15) +
                        rightJustify("Cost", 10) +
                        rightJustify("Qty", 5) +
                        rightJustify("Extended Cost", 15) +
                        rightJustify("GST", 5) +
                        rightJustify("Total Cost", 13));
    //          Print Records
              for(int i=0; i<validCounter; i++)
                   extendedCost = valid.CalculateExtendedCost();
                   extendedCost = roundDouble(extendedCost, 2);
                   GST = valid[i].CalculateGST();
                   GST = roundDouble(GST, 2);
                   totalCost = extendedCost + GST;
                   totalCost = roundDouble(totalCost, 2);
    //               justify method ensures all values are of the same size
                   System.out.println(//leftJustify(i+"",3) + ": " +
                             leftJustify(valid[i].GetName(), 50) +
                             leftJustify(valid[i].GetUPC(), 15) +
                             rightJustify(valid[i].getClass()+"", 10) +
                             rightJustify(valid[i].GetQuantity()+"", 5) +
                             rightJustify(extendedCost+"", 10) +
                             rightJustify(GST+"", 10) +
                             rightJustify(totalCost+"", 10));
                   sumOfExtendedCost += extendedCost;
                   sumOfGST += GST;
                   sumOfTotalCost += totalCost;
         private static void sortByName(Product1 [] ValidProduct, int logicalSize) throws Exception
              Product1 temp;
              for (int outer = logicalSize-1; outer > 1; outer --)
                   for (int inner = 0; inner < outer; inner ++)
                        if (ValidProduct[inner].GetName().compareToIgnoreCase(ValidProduct[inner+1].GetName())>0)
                             temp = ValidProduct[inner];
                             ValidProduct[inner] = ValidProduct[inner + 1];
                             ValidProduct [+ 1] = temp;
         public static void binarySearchByName(Product1 [] ValidProduct, int logicalSize)
              int high = logicalSize - 1;
              int low = 0;
              int mid = 0;
              int count = 0;
              int compare = 0;
              boolean found = false;
              System.out.print("Enter a product name");
              String product = input.nextLine();
              while (high >= low && !found)
                   count += 1;
                   mid = (high + low) / 2;
                   compare = ValidProduct[mid].GetName().compareToIgnoreCase(product);
                   if (compare == 0)
                        System.out.println("Found: " + ValidProduct[mid].GetName());
                        found = true;
                   else if (compare < 0)
                        low = mid + 1;
                   else
                        high = mid - 1;
              if (!found)
                   System.out.println(product + " not found.");
              System.out.println(count + " steps");
              System.out.println();
         public static String leftJustify(String field, int width)
              StringBuffer buffer = new StringBuffer(field);
              while (buffer.length() < width)
                   buffer.append(' ');
              return buffer.toString();
         public static String rightJustify(String field, int width)
              StringBuffer buffer = new StringBuffer(field);
              while (buffer.length() < width)
                   buffer.append(' ');
              return buffer.toString();
         public static void displayValidRecords(Product1 [] ValidProduct, int logicalSize) throws Exception {
              long longMAX_POSSIBLE_UPC_CODE = 999999999999L;
              // set input stream and get number
              Scanner stdin = new Scanner(System.in);
              System.out.print("Enter a 12-digit UPC number: ");
              long input =stdin.nextLong();
              long number = input;
              // determine whether number is a possible UPC code
              if ((input < 0)|| (input > longMAX_POSSIBLE_UPC_CODE)) {
                   // not a UPC code
                   System.out.println(input +"is an invalid UPC code");
              else {   
                   // might be a UPC code
                   // determine digits
                   int d12 = (int) (number % 10);
                   number /= 10;
                   int d11 = (int) (number % 10);
                   number /= 10;
                   int d10 = (int) (number % 10);
                   number /= 10;
                   int d9 = (int) (number % 10);
                   number /= 10;
                   int d8 = (int) (number % 10);
                   number /= 10;
                   int d7 = (int) (number % 10);
                   number /= 10;
                   int d6 = (int) (number % 10);
                   number /= 10;
                   int d5 = (int) (number % 10);
                   number /= 10;
                   int d4 = (int) (number % 10);
                   number /= 10;
                   int d3 = (int) (number % 10);
                   number /= 10;
                   int d2 = (int) (number % 10);
                   number /= 10;
                   int d1 = (int) (number % 10);
                   number /= 10;
                   // compute sums of first 5 even digits and the odd digits
                   int m = d2 + d4 d6 d8 + d10;
                   int n = d1 + d3 d5 d7 + d9 + d11;
                   // use UPC formula to determine required value for d12
                   int r = 10 - ((m +3*n) % 10);
                   // based on r, can test whether number is a UPC code
                   if (r == d12) {
                        // is a UPCcode
                        System.out.println(input+" is a valid UPC code");
                   else {   
                        // not a UPCcode
                        System.out.println(input+" is not valid UPC code");
    Any help would be great thanks !!
    Take care,

    1) It's your problem that you waited until the last minute before you went for help...not ours. We'll give your problem the same attention as anyone elses...therefore your problem isn't any more urgent than any other problem here.
    2) I don't intend on doing your entire assignment. Nor do I intend on reading all of it. If you need help with a specific requirement, then post the information/code relevant to that requirement. I don't know how to help you when you bury the problem inside a 9 mile long essay.
    3) Post code in tags so it's formatted and readable. (there's a *code* button up above that makes the tags for you).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Fill in the Blanks and Win a Prize!

    Well maybe no prize but I would be grateful. Our class was assigned 2 array example programs with key bits of code missing. Iv'e understood everything pretty well up till this point, but arrays have me confused. I've spent hours on these things but always wind up with a compiling error of some sort. The instuctions and intended output are commented on the top, any help would be greatly appeciated.
    Here is program 1.....
    Sample Output:
    *** start program ***
    Average Integer Score: 18
    Count of Integers Less Than Average: 3
    *** end program ***
    Input:
    An integer array of ten numbers: 20,17,9,29,19,9,19,20,20,19
    Compile-time array with initialization list of numbers.
    NOTE: In main() function
    Processing:
    Function: computeAverage(final int[], final int):int
    countLessThan(final int[], final int, final int):int
    Output:
    Function: display(final int, final int):void
    Display as shown in sample output.
    public class Arrays1D_Ex02
    public static void main(String [] args)
    // finalants
    final int SIZE = _____;
    // local data
    int intAverage = 0;
    int count = 0;
    // data declaration(s) & initialization(s)
    // array data: use data from sample output above
    // TODO: declare & initialize array of ten integers
    int numbers[]={___________________________________};
    // start the program
    System.out.println( "*** start of Arrays1D_Ex02.java program ***");
    System.out.println();
    // Compute & return integer average of the array
    // TODO: call computeAverage()function,
    // which returns average of numbers
    intAverage = computeAverage(numbers);
    // Compute & return count of array values less than integer average
    // TODO: call countLessThan() function,
    // which returns count of numbers less than the average
    count = countLessThan(numbers, intAverage);
    // display the required output
    // TODO: call display function,
    // passing integer average & count of numbers less than average
    display(intAverage, count);
    // terminate the program
    System.out.println();
    System.out.println();
    System.out.println( "*** end of Arrays1D_Ex02.java program ***");
    return;
    } // end main()
    // Function Name: display(final int, final int):void
    // Purpose: to display integer average & count less than average
    // Values received: integer average, count
    // Values returned: <none>
    // Notes:
    // display label "Average Integer Score: "
    // display integer average
    // display label "Count of Integers Less Than Average: "
    // display count
    // TODO: code the display function
    private static void display(final int average, final int count)
    // display labels and data
    System.out.print(_________________________);
    System.out.println(_____________);
    System.out.print(_________________________________);
    System.out.println(___________);
    // TODO: code the computeAverage function
    private static int computeAverage(final int[] numbers)
    // local variables (if needed)
    int sum = 0;
    int intAverage = 0;
    // compute sum
    for(int i = 0; i < numbers.length; i++)
    sum ___ numbers;
    // compute integer average
    intAverage = sum / numbers.length;
    // return integer average
    return __________;
    // TODO: code the countLessThan function
    private static int countLessThan(_________________,
    // local variables (if needed)
    int count = 0;
    // count number of values less than average
    for(int i = 0; i < numbers.length; i++)
    if(numbers[i] ___ average)
    count++;
    // return count
    return count;
    } // end class
    -------------------Here is program 2------------------------------------------------------------------------------------------------
    Sample Output:
    *** start program ***
    Number Count
    1 1
    2 2
    3 5
    4 2
    5 3
    *** end program ***
    Input:
    An integer array of 13 numbers: 3, 4, 5, 3, 2, 1, 3, 4, 5, 3, 2, 3, 5
    An integer array of 5 counts intialized to all 0.
    Compile-time arrays with initialization list of numbers.
    NOTE: In main() function
    Processing:
    Function: countValues(final int[], final int, int[]):void
    The values in the numbers array are counted and the correct cells of the count array are increment.
    Output:
    Function: display(final int[], final int):void
    Display as shown in sample output.
    public class Arrays1D_Ex03KEY
    public static void main(String [] args)
    // finals
    final int VALUES_SIZE = 13;
    final int COUNT_SIZE = 5;
    // local data
    // data declaration(s) & initialization(s)
    // array data: use data from sample output above
    // TODO: declare & initialize array of ten integers
    int [] numbers = ________________________________;
    int [] counts = new _____________________________;
    // start the program
    System.out.println("*** start of Arrays1D_Ex03.java program ***");
    System.out.println();
    // Compute count of values
    // TODO: call countValues() function
    // passing numbers array, array size, count array
    countValues(_____, VALUES_SIZE, _____);
    // display the required output
    // TODO: call display function,
    // passing count array & size
    display(_____, COUNT_SIZE);
    // terminate the program
    System.out.println();
    System.out.println();
    System.out.println( "*** end of Arrays1D_Ex03.java program ***");
    return;
    } // end main()
    // Function Name: display(final int[], final int):void
    // Purpose: to display count of values
    // Values received: array of counts, array size
    // Values returned: <none>
    // Notes:
    // display column headings using manipulators
    // in a 'for' loop, print the number and count
    // TODO: code the display function
    private static void display(______________, __________________)
    // print column headings
    System.out.print("Number");
    System.out.println("\tCount");
    // print detail lines (format on one line, display on next)
    // use a 'for' loop
    for(int i = 0; i < size; i++)
    // TODO: print out the number
    System.out.print(___________);
    // TODO: print out the count
    System.out.println( "\t" + _____________);
    // TODO: code the countValues function
    private static void countValues(________________,
    final int size,
    // TODO: determine value and increment count
    // use a 'for' loop
    // HINT: use nested arrays & their indexes

    You will (usually) get better help with homework if you make some effort to complete it, then post your problems. Just posting homework often causes people to reply with flames. Also, when posting code use the code and /code tags as explained in the Formatting Help link (right above the text box when you compose a post).
    So try filling in your blanks and comment the lines where you have done so. Then post the smallest amount of code that should compile, but does not, and be sure to post the full exact error messages.
    Another tip, compile code in small steps - write some then compile it. You will have to write enough code to include dependent variables and methods but it is much easier to solve 3 compiler errors than 30.

  • Creation of a database engine for mobile devices using j2me

    am trying to develop a database engine for mobile devices.. it is to develop a miniature version of the DBMS that
    can be deployed on a mobile phone..I have to develop my own code for performing tasks such a s creating a table,
    inserting values into it, selecting from it etc..
    I limited my self to develop the software so that it can perform 3 functionalities of create, insert,select..
    I should be taking the details such as table name and its parameters from the user and then should be able to
    create a suitable data structure for it(i tried to develop a class)...
    Usage of RMS package helps me partially in this.. I did that and ll be doing that..
    I got stuck while developing the code for creation of a table.. I am facing problems in creating a dynamic data
    structure for a table and also to use such data structure else where in my project..
    I need help in developing an algorithm for this..
    I would be very grateful to u all if u help me out in developing the code for this project..

    I'm sorry for the amount of time it took me to get back. Derby is an open source database written entirely in Java. I do not know if it can support resource constrained devices like MIDP compliant, but may work okay with CLDC.
    But outside of Derby being a solution, let me give you a few ideas off the top of my head.
    Set up a database server in a separate thread. This server will really be your controller for RMS access.
    Since RMS is just a big sequential 'pipe' you will have to think of data as 'frames' - (starttable) (tableID) (tablename) (data) (tablename) (data).....(endtable).
    When you need to write additional data, just append it to the end of the RMS object.
    When you need to retrieve data, thing are more complex.
    1. Read in all data, looking for your particular tableID. This may be made much easier using RMS filters - (I'm not sure, I've never used them)
    2. Once start of table of interest is found, stick the data elements in either a java vector or array until you reach the table end identifier. I think vector will be a better choice - trust me. (I think its available in J2ME...)
    3. Package this into a do while loop until the element you are searching for is read. If you need to do some sorts on the data or something else that requires the all the data to be present then you need all the data for that particular table. One thing will always be clear. The first data you grab will always be some start table identifier and the last data you grab will be an end table identifier. We just don't know which table because of how we put stuff in the RMS resource.
    This provides you a few positives as well as negatives:
    Positive:
    1. Fast data writes, no need to search for a particular table before accessing it, nor do you need to search for an index in that table.
    2. When looking for data, data may* be found without searching through the entire table. This is accomplished with RMS filters or logic test within the RMS read loop.
    Negative:
    1. Slow when all data of a table is needed (i.e. compute sums or averages of entries). The entire RMS database must be read to ensure all the entries are searched. An example of how this is a problem is as follows: You have 5000 entries in you RMS database resource and you are looking to compute the average of a value in some table. When you first wrote the data to the table, it was done sequentially and no other data for that table exist. But we can't tell if that's the case, so we have to read through all 5000 entries to make sure we looked for every piece of data.
    Beacuse of this issue, this database structure, performance may be fine for 50K - 100K entries (depending on table element size), if the reading requirements don't force full data reads. Otherwise, 25K may be an upper limit.
    I hope this helps.
    Edited by: estarkey on Mar 17, 2009 9:15 PM
    Edited by: estarkey on Mar 17, 2009 10:01 PM

Maybe you are looking for