Update using an aggregate function

Hi all, while I'm a first time poster I've searched this forum as much as I can for a solution to this problem.
I'm trying to update an end_time column in a table using the values in the start_time column.
Here's a simplified example of what I want:
update table
set end_time = lag(start_time) over (order by start_time desc)-1;
So,
KEY START_TIME
1 7/1/1998
2 5/1/1998
3 4/1/1998
4 6/1/1995
becomes
KEY START_TIME END_TIME
1 7/1/1998
2 5/1/1998 6/30/1998
3 4/1/1998 4/30/1998
4 6/1/1995 3/31/1998
While I'd love this statement to be valid, does anyone know an alternative? I'd like to use the merge statement but I'm developing under an oracle 8i environment. I'm saving a pl loop as a last option.

It is possible that with large data sets this first solution could be slow. The following query may choose full table scans and sort merges which might be more preferred for big tables. Also, the actual updates in the following MERGE will not execute unless the values have actually changed:
MERGE INTO foo f USING
SELECT a.start_date, min(b.start_date)-1 end_date
FROM   foo a,
        foo b
WHERE  b.start_date(+) > a.start_date
GROUP BY a.start_date
) bar
ON (f.start_date = bar.start_date)
WHEN MATCHED THEN UPDATE SET f.end_date = bar.end_date
WHERE nvl(f.end_date,to_date('01-jan-1900','dd-mon-yyyy')) != nvl(bar.end_date,to_date('01-jan-1900','dd-mon-yyyy'));Greg Pike
http://www.singlequery.com

Similar Messages

  • Problems with After Report trigger Updating using User-defined functions

    Hi,
    I have a report which uses SQL to select data that uses a user-defined stored function in the WHERE clause.
    I use the same SQL in the After Report trigger with and UPDATE statement to flag all records selected as being run.
    Data is being selected by the report no problem, but the records are not being updated. In a test, If I remove the conditions using the user functions, the records update as expected. In Live conditions I must have these conditions in the script.
    I originally tried putting the UPDATE in a formual column, but that would not fire on records where that page was not paged through (or paged to end) in the Runtime Previewer.
    Can anyone advise?

    In case anyone is interested.
    The issue was that the stored functions have roles assigned for security.
    PL/SQL for After Report doesn't seem to recognise the roles having been assigned for the report, so the implicit cursor update/select I had wouldn't work.
    I changed the SELECT into an explicit CURSOR and introduced a FOR LOOP, keeping the UPDATE as an implicit statement.
    I know see this was more of a PL/SQL issues than a report one, but such is life. So if anyone feels the urge to move it to the PL/SQL forum, then feel free!!
    Have a problem free afternoon. :-)

  • Using an Aggregate Function in a Sub-SELECT

    Ok. I have this Sub-SELECT and I'd like to base my outside query based on the resyult set of my inner Sub-SELECT which contains an Aggregate function.
    Is that possible???
    Here's the Query...
    SELECT *
    FROM CUSTPRO.CPM_PND_TRAN_HDR CPMPNDTH
    INNER JOIN (SELECT CPMPNDT2.ky_pnd_seq_trans,
    CPMPNDT2.id_ba_esco,
    CPMPNDT2.ky_ba,
    CPMPNDT2.ky_enroll,
    MAX(CPMPNDT2.dt_billed_by_css)
    FROM CUSTPRO.CPM_PND_TRAN_HDR CPMPNDT2
    WHERE CPMPNDT2.ky_pnd_seq_trans IN (6544937)
    GROUP BY CPMPNDT2.ky_pnd_seq_trans,
    CPMPNDT2.id_ba_esco,
    CPMPNDT2.ky_ba,
    CPMPNDT2.ky_enroll) DERIVE1
    ON CPMPNDTH.id_ba_esco = DERIVE1.id_ba_esco
    AND CPMPNDTH.ky_ba = DERIVE1.ky_ba
    AND CPMPNDTH.ky_enroll = DERIVE1.ky_enroll
    AND CPMPNDTH.dt_billed_by_css = ????DERIVE1.MAX(CPMPNDT2.dt_billed_by_css)???
    How can I designate that last qualifier ????....
    PSULionRP

    You should give your aggregate function a column-alias as in:
    SELECT *
    FROM   custpro.cpm_pnd_tran_hdr cpmpndth
           INNER JOIN (SELECT   cpmpndt2.ky_pnd_seq_trans,
                                cpmpndt2.id_ba_esco,
                                cpmpndt2.ky_ba,
                                cpmpndt2.ky_enroll,
                                Max(cpmpndt2.dt_billed_by_css) as XXX    -- ADDED THIS.
                       FROM     custpro.cpm_pnd_tran_hdr cpmpndt2
                       WHERE    cpmpndt2.ky_pnd_seq_trans IN (6544937)
                       GROUP BY cpmpndt2.ky_pnd_seq_trans,
                                cpmpndt2.id_ba_esco,
                                cpmpndt2.ky_ba,
                                cpmpndt2.ky_enroll) derive1
             ON cpmpndth.id_ba_esco = derive1.id_ba_esco
                AND cpmpndth.ky_ba = derive1.ky_ba
                AND cpmpndth.ky_enroll = derive1.ky_enroll
                AND cpmpndth.dt_billed_by_css = derive1.XXX
    /

  • Update statement with Aggregate function

    Hi All,
    I would like to update the records with sum of SAL+COMM+DEPTNO into SALCOMDEPT column for each row. Can we use SUM function in Update statement. Please help me out this
    See below:
    Table
    CREATE TABLE EMP
    EMPNO NUMBER(4) NOT NULL,
    ENAME VARCHAR2(10 CHAR),
    JOB VARCHAR2(9 CHAR),
    MGR NUMBER(4),
    HIREDATE DATE,
    SAL NUMBER(7,2),
    COMM NUMBER(7,2),
    DEPTNO NUMBER(2),
    SALCOMDEPT NUMBER
    Used update statement :
    UPDATE emp e1
    SET e1.salcomdept= (select sum(sumsal+comm+deptno) from emp e2 where e2.empno=e1.empno)
    WHERE e1.deptno = 10
    commit
    Thanks,
    User

    Adding these columns makes no sense, so I'll assume this is just an exercise.
    However, storing calculated columns like this is generally not a good idea. If one of the other columns is updated, your calculated column will be out of sync.
    One way around this is to create a simple view
    SQL> CREATE view EMP_v as
      2  select EMPNO
      3        ,ENAME
      4        ,JOB
      5        ,MGR
      6        ,HIREDATE
      7        ,SAL
      8        ,COMM
      9        ,DEPTNO
    10        ,(nvl(sal,0) + nvl(comm,0) + nvl(deptno,0)) SALCOMDEPT
    11  from   emp;
    View created.
    SQL> select sal, comm, deptno, salcomdept from emp_v;
                     SAL                 COMM               DEPTNO           SALCOMDEPT
                     800                                        20                  820
                    1600                  300                   30                 1930
                    1250                  500                   30                 1780
                    2975                                        20                 2995
                    1250                 1400                   30                 2680
                    2850                                        30                 2880
                    2450                                        10                 2460
                    3000                                        20                 3020
                    5000                                        10                 5010
                    1500                    0                   30                 1530
                    1100                                        20                 1120
                     950                                        30                  980
                    3000                                        20                 3020
                    1300                                        10                 1310
    14 rows selected.

  • Dynamic SQL and use of aggregate functions

    Hello Forum members,
    I'm trying to create dynamic SQL in a function module and return the MAX value of a field. 
    I am passing in a parameter called CREATE_FIELD_NAME, and my SQL is
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    I also tried:
    SELECT MAX((CREATE_FIELD_NAME)) INTO (CREATE_DATE) FROM (TABLE_NAME).
    But abap is not recognizing my variable as a variable in either case, but rather, as a field name.
    Anyone know a way around this?
    Thanks in advance,
    Jeff
    Here is my program:
    FUNCTION ZJLSTEST4.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(TABLE_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(CREATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(UPDATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"  EXPORTING
    *"     VALUE(MAX_DATE) LIKE  SY-DATUM
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
          UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    ENDSELECT.
    *SELECT MAX((UPDATE_FIELD_NAME)) INTO (UPDATE_DATE) FROM (TABLE_NAME).
    *ENDSELECT.
    IF CREATE_DATE > UPDATE_DATE.
       MAX_DATE = CREATE_DATE.
    ELSE.
       MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    ENDFUNCTION.

    Max is right, you need the spaces, as in my example.
    You might like to try this:
    data: l_CREATE_FIELD_NAME) LIKE MAKT-MAKTX,
          l_UPDATE_FIELD_NAME) LIKE MAKT-MAKTX.
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
    UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    concatenate 'MAX(' create_name ')' into l_create_name separated by space.
    concatenate 'MAX(' update_name ')' into l_update_name separated by space.
    SELECT SINGLE (l_CREATE_FIELD_NAME)
    INTO CREATE_DATE FROM (table_name).
    SELECT SINGLE (l_updATE_FIELD_NAME)
    INTO updATE_DATE FROM (table_name).
    IF CREATE_DATE > UPDATE_DATE.
    MAX_DATE = CREATE_DATE.
    ELSE.
    MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    If it still fails please post the latest abap code for us to check.

  • Group By Without Using Any Aggregate Function

    L1                                L2
    54654               414.00
    654654               237.60
    654654     
    54654               1,108.80
    654654               1,136.00
    654654               5,956.00
    NOW I WANT OUTPUT LIKE
    L1               L2           sum
    54654     414.00    1,522.80
    54654     1,108.80  1,522.80
    654654     1,136.00  7,329.60
    654654     237.60    7,329.60
    654654     5,956.00  7,329.60
    HERE GROUP IS L1 SO
    L1  54654  414
         54654  1108  SO TOTAL IS 1522

    I USE FOLLOWING LOGIC:-
      sort i_data by lrnum.
       loop at i_data.
           on change of i_data-lrnum.
            if sy-tabix = 1.
              else.
               itab-lrfriegh = tot_sum.
               append itab.
               clear itab.
               clear i_data.
               clear tot_sum.
              endif.
              endon.
            at end of lrnum.
              move i_data to itab.
            endat.
              tot_sum = tot_sum + i_data-afriegh.
            at last.
              itab-lrfriegh = tot_sum.
              append itab.
              clear itab.
              clear i_data.
              clear tot_sum.
            endat.
         endloop.
    CLOSE THREAD
    Edited by: krupa jani on Nov 22, 2008 10:10 AM

  • How to use multiple aggregate functions in single query

    hi to all
    The output will be giving first_name,last_name,max(salary),min(salary) and the output will be department wise.From employees table in single query
    output will be:
    first_name|last_name|max(salary)|min(salary)

    SELECT first_name||' '||last_name as ename,
           MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
           MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
    FROM   emp
    ORDER BY deptno, sal;Edited by: Ramio on Jan 10, 2012 10:43 PM

  • Using aggregate function pulls an additional table in join

    Hello,
    We're facing a wierd scenario whereby using an aggregate function in a report brings an additional table in the query, which should not be included. Please throw some light on this if you have any idea why this would happen. Here are the details
    OBIEE version: 10.1.3.4
    I pull 2 columns in my report - Col1 (numeric column from Dim A), Col2 (date column from Dim B)
    I have already set an implicit fact column in that subject area (Col3 from Fact X)
    Now when I run this report, the FROM clause of the sql correctly shows Dim A, Dim B, Fact X
    Later, I apply a MAX function on Col2 (date column from Dim B). Ideally, the FROM clause of my sql should still be the same. But here is what happens...
    FROM Dim A, Dim B, Fact X, Fact Y (Bridge table).
    Fact Y is a bridge table that we are using in this subject area. But there is no reason why this table should get pulled in this query just by using an aggregate function in it.
    Your thoughts and insights will be highly appreciated.
    Thanks,
    Vahib

    Did you apply MAX in the aggregate function section? If that is the case, OBIEE is forced to consider logical table for Dim B as a fact and brings in Y as a way to resolve the join between two facts.
    Try setting up a new fact and create MAX column there. See if it resolves that problem or not. You may also want to bring Dim B in the LTS of the main fact and create a column with MAX aggregation. That should work too.

  • Pivot table in BI Publisher: Different aggregate functions in data columns

    Hi, everyone!
    I`ve got some troubles with pivot table in my rtf-template.
    Here is my xml:
    <ROWSET>
         <ROW>
              <_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
              <_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000003</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
              <_BI_MONTH_DEBET_._BI_DEBET_SUM_>0.0</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
              <_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
              <_BI_CALENDAR_._MONTH__>8</_BI_CALENDAR_._MONTH__>
         </ROW>
         <ROW>
              <_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
              <_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000004</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
              <_BI_MONTH_DEBET_._BI_DEBET_SUM_>165.58</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
              <_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
              <_BI_CALENDAR_._MONTH__>7</_BI_CALENDAR_._MONTH__>
         </ROW>
         <ROW>
              <_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
              <_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000004</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
              <_BI_MONTH_DEBET_._BI_DEBET_SUM_>165.58</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
              <_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
              <_BI_CALENDAR_._MONTH__>7</_BI_CALENDAR_._MONTH__>
         </ROW>
    ...... and so on..
    </ROWSET>
    In the pivot table i`d like to see one row for every BISUBRF_MO_._MUN_NAME_ using BICALENDAR_._YEAR__ and BICALENDAR_._MONTH__ as measures and sum of BIMONTH_DEBET_._BI_DEBET_SUM_ and count of unique (or at least just count of) BIPERS_ACCOUNT_CARD_._BI_PAC_NMB_ in cells.
    I create a pivot table using wizard, everything ok except one thing: as i understand, in pivot table for data in rows we can use only one kind of aggregate function e.g. only sum or only count.
    Is there any way to use different aggregate functions in data cells?
    Thank you

    As you can see, when we use crosstab tag we can specify only one aggregate function for data cells.
    Is there any way to get in XSL-FO (where we can what really happens) instead of:
    <T1>
    <xsl:value-of select="sum(current-group()/_BI_PERS_ACCOUNT_CARD_._BI_PAC_UNID_)"/>
    </T1>
    <T2>
    <xsl:value-of select="sum(current-group()/_BI_MONTH_DEBET_._BI_DEBET_SUM_)"/>
    </T2>
    this
    <T1>
    <xsl:value-of select="sum(current-group()/_BI_PERS_ACCOUNT_CARD_._BI_PAC_UNID_)"/>
    </T1>
    <T2>
    <xsl:value-of select="count(current-group()/_BI_MONTH_DEBET_._BI_DEBET_SUM_)"/>
    </T2>
    Edited by: user12115038 on 26.10.2009 8:08

  • Using round off function in where clause

    Hi All,
    I'm trying to use round off function in where clause, I seek help in completing this script.
    WITH CR_Details AS
    (Select
    request_id,
    parent_request_id,
    fcpt.user_concurrent_program_name Request_Name, phase_code, status_code,
    round((fcr.actual_completion_date - fcr.actual_start_date),3) * 24 * 60 as Run_Time,
    round(avg(round(to_number(actual_start_date - fcr.requested_start_date),3) * 1440),2) wait_time,
    fu.User_Name Requestor,
    fcr.argument_text parameters,
    to_char (fcr.requested_start_date, 'MM/DD HH24:mi:SS') requested_start,
    to_char(actual_start_date, 'MM/DD/YY HH24:mi:SS') ACT_START,
    to_char(actual_completion_date, 'MM/DD/YY HH24:mi:SS') ACT_COMP,
    fcr.completion_text
    From
    apps.fnd_concurrent_requests fcr,
    apps.fnd_concurrent_programs fcp,
    apps.fnd_concurrent_programs_tl fcpt,
    apps.fnd_user fu
    Where 1=1
    and fcr.concurrent_program_id = fcp.concurrent_program_id
    and fcp.concurrent_program_id = fcpt.concurrent_program_id
    and fcr.program_application_id = fcp.application_id
    and fcp.application_id = fcpt.application_id
    and fcr.requested_by = fu.user_id
    and fcpt.language = 'US'
    and fcr.actual_start_date like sysdate )
         select crd.*
         from CR_Details crd
         where Run_time <> '0'
         AND wait_time <> '0'
    GROUP BY
    crd.request_id,
    crd.parent_request_id,
    crd.fcpt.user_concurrent_program_name,
    crd.requested_start_date,
    crd.User_Name,
    crd.argument_text,
    crd.actual_completion_date,
    crd.actual_start_date,
    crd.phase_code,
    crd.status_code,
    crd.resubmit_interval,
    crd.completion_text,
    crd.resubmit_interval,
    crd.resubmit_interval_unit_code,
    crd.description
    Not sure about the GROUPBY function referencing the "crd." .

    Hi,
    The best thing for you to do is start over. Start as small as possible, then take baby steps.
    Pick one of the tables; fcr perhaps, and write a query that just uses that table, like this:
    SELECT    *
    FROM       apps.fnd_concurrent_requests     fcr
    WHERE       fcr.actual_start_date          >= TRUNC (SYSDATE)
    AND       fcr.actual_start_dt          <  TRUNC (SYSDATE) + 1
    ;(I think this is what you meant to do when you said "... LIKE SYSDATE".)
    Make sure this little query gets credible results. When that tiny query is working perfectly, add another line or two. You can cut and paste code from what you posted, if that helps you.
    If you get stuck, post the last version of your code that worked perfectly, and the latest version (only a line or two bigger) that has the problem. Describe what the problem is. If you get an error, post the complete error message. In any event, post CREATE TABLE and INSERT statements for all the tables and columns needed to run the query, and the results you want to get from that query.
    When you post any code, format it, so that how the code looks on the screen gives some clues about how it is working.
    When you post any formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If you going to use the AVG function in the sub-query, then you probably need to do a GROUP BY in the sub-query.
    If you're not using any aggregate functions (like AVG) in the main query, then you probably don't want to do a GROUP BY in the main query.
    I know this is a lot of work.  I'm sorry.  If there was an easier way, I wouldn't ask you to do all this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Aggregate Function in SQL subquery

    Hello,
    I am trying to use the following syntax and it is saying I can't use an aggregate function in a subquery. I can't use a GROUP BY in this case because if another field in the project table (such as status) is different, that project will show up twice.
    So in this case I am using this syntax to show the most recent quote within the project.
    SELECT PROJECT.*, QUOTE.QuoteDate, QUOTE.QuoteCode
    FROM PROJECT LEFT JOIN QUOTE ON PROJECT.ProjectID = QUOTE.ProjectID
    WHERE QUOTE.QuoteDate=(SELECT Max(Q.QuoteDate) FROM QUOTE Q WHERE Q.ProjectID = PROJECT.ProjectID);
    My goal here is to show the most recent quote within each project (there can be multiple revisions of a quote within each project). I want to show other fields such as the status of the quote, but if the status is different between quotes, the GROUP BY on that
    field will cause it to be listed more than once. All I want to show is the most recent quote for each project.
    Let me know if this isn't clear.
    Thanks.

    Try the below querySELECT P1.projectID,p1.QuoteDate, Q1.QuoteCode,p1.*
    FROM PROJECT P1 inner join (SELECT Q.ProjectID,Max(Q.QuoteDate) QD FROM QUOTE Q group by Q.ProjectID) Q1 on Q1.ProjectID = P1.ProjectID and Q1.QD=P1.QuoteDate-Prashanth

  • Insert & Update using Writeback in a single Report

    Hi,
    Here is requirement:
    In the single report where the user has to do the Insert & update using the writeback functionality.
    below is the XMl:
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="SUBMITBUTTON">
    <XML>
    <writeBack connectionPool="CSDK">
    <insert>INSERT INTO HSCRTARGETLOOKUP(SLA_TYPE,TARGET_AVAILABILITY,TARGET_MTTR) VALUES ('@{c0}', @{c1}, @{c2})</insert>
    <update>UPDATE HSCRTARGETLOOKUP SET TARGET_AVAILABILITY = @{c1}, TARGET_MTTR = @{c2} WHERE SLA_TYPE = '@{c0}'</update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    Can you please let us know whether both insert & update will work at the same time using a single report.
    Thanks in Advance
    Siva

    Hi,
    Insert & update is working with the Single xml file:
    here it is how i have done:
    in the 1st criteria i have taken three columns and made union with the 3 dummy columns.
    in the 1st dummy column: CASE WHEN 1= 0 THEN HSCRTARGETLOOKUP.SLA_TYPE ELSE NULL END
    2nd dummy column: CAST('' AS INT)
    3rd dummy column: CAST('' AS INT)
    below is the single XML file which is working for both insert & update
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="STATES">
    <XML>
    <writeBack connectionPool="XXXX">
    <insert>INSERT INTO HSCRTARGETLOOKUP(SLA_TYPE,TARGET_AVAILABILITY,TARGET_MTTR) VALUES ('@{c0}', @{c1}, @{c2})</insert>
    <update></update>
    <update>UPDATE HSCRTARGETLOOKUP SET TARGET_AVAILABILITY = @{c1}, TARGET_MTTR = @{c2} WHERE SLA_TYPE = '@{c0}'</update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    Hope it works for you also.

  • PDF Download doesn't keep an aggregate function result

    Hello,
    I have an interactive report that has a sum that I created using the aggregate function. When I download to a PDF, there is no sum.
    Does anyone have a solution?
    Thanks,
    Matt

    Hi Matt
    At this time the Interactive Report Regions (IRR) don't support this functionality. I'm assuming that's what you're kicking-off the PDF generation from.
    The only solution I am aware of is to set up an APEX Report & Template that contains the SUM function you require displayed in your PDF. Whilst this will deliver the result you're after, you will lose the flexibility of the IRR.
    You may also want to add your comments/thoughts to this thread I started earlier.
    [http://tinyurl.com/peu6b2]
    If you need help with the APEX Report & Template option, please let me know.
    Kind regards
    Simon Gadd

  • Select into aggregate function

    Hi,
    I have the following PL/SQL block that I am testing. The block reads a list of values from a local file and inserts the values into a select statement that uses an aggregate function. Here is my code:
    DECLARE
    f utl_file.file_type;
    n COLa%TYPE; --holds values from the file
    v COLb%TYPE; --holds value returned by select statement
    BEGIN
    f := utl_file.fopen(dir,file.txt,'R');
    loop -- loop through file
         utl_file.get_line(f,n);
         if length(n) <> 0 then
              SELECT max(A0.COLa) into v
              FROM (SELECT AOB.COLa, A0.COLb
              FROM TAB1 A0,TAB2 A0B
              WHERE (A0.PK=A0B.PK) and A0B.COLa = n) A0;          
              IF SQL%rowcount = 0 THEN
                   dbms_output.put_line('no rows);
              else
                   dbms_output.put_line(v);
              end if;                    
         end if;     
    end loop;
         utl_file.fclose(f);     
    end;
    Here is the error I get:
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 656
    ORA-06512: at line 12
    I checked the database for the first couple of values in the list and got rows. I also ran a simple PL/sql code to print values in the file successfully. So I dont know why it is returning no data found. From what I understand select into statement using aggregate functions will never raise this exception, so why I am getting this error?
    Thanks.

    Hi,
    Actually, the SELECT ... INTO isn't the problem here.
    Look at the error message:
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 656
    ORA-06512: at line 12The error is ocurring inside utl_file, which is being called at line 12 of your code. (That must be
    utl_file.get_line(f,n);)
    Utl_file.get_line raises NO_DATA_FOUND when it reaches the end of the file. (If it didn't you'd have an infinite loop, since your code doesn't have any exit strategy.)
    You can put the call to get_line in its won BEGIN-EXCEPTION-END block, and trap the NO_DATA_FOUND error.
    For example:
    end_of_file := 0;
    WHILE  end_of_file = 0;
    loop -- loop through file
        BEGIN
            utl_file.get_line(f,n);
            if length(n) != 0 then          -- Use !=, because you can't post &lt;&gt; on this site
                SELECT  max(A0B.COLa)     -- No sub-query needed
                into    v
                FROM    TAB1 A0
                ,         TAB2 A0B
                WHERE   (A0.PK   = A0B.PK)
                and         A0B.COLa = n;
                IF SQL%rowcount = 0 THEN     -- Not needed: SELECT MAX ... without GROUP BY always returns 1 row
                    dbms_output.put_line('no rows);
                else
                    dbms_output.put_line(v);
                end if;
            end if;
        EXCEPTION
            WHEN  NO_DATA_FOUND
            THEN
                end_of_file = 1;
        END;
    end loop;Edited by: Frank Kulash on Jul 17, 2009 2:51 PM

  • Running Aggregate Functions, Attribute or Measure?

    Hi Guys:
    I wonder if this is a bug in BIEE 11g? I am using 11.1.1.6.
    My requirement is quite simple, I have a measure, and I want to show this measure as a cumulative curve by month. For example, let's suppose there are three columns in Criteria:
    Month, Amount, RSUM(Amount)
    Then I plot a curve by RSUM(Amount) vs. Month. In BIEE 10, there is no problems. However in 11.1.1.6, I got an error. I look into the table and found that, after using running aggregate functions, like RSUM or MSUM, the column becames Attribute, instead of Measure. In other word, although I can see the RSUM(Amount) column in Criteria page shows a yellow icon, it turns into blue in Results page! Since it becames Attributes in Results page, I cannot drag RSUM(Amount) into Measures area in Line Graph. I can see the correct values in Table view, but got error in Line Graph view.
    Why the column properties are different between Criteria and Results? And are there any workaround to plot a cumulative curve? I dont want Parete graph.
    Thanks
    Larry

    Hi Larry,
    I do not think this is any bug in .6 and I just gave a try successfully to confirm that too. My test case follows
    1. Created an analysis with Period.Month and Measures.Value
    2. Added another measure and changed the formula of Measures.Value as RSUM(Measures.Value) and still see it to be a measure as expected.
    3. Navigated to results section and added all kind of graphs to notice that it is behaving as expected.
    Can you let us know, what error are you hitting at in the graph?
    Thank you,
    Dhar

Maybe you are looking for

  • How to restrict the decimal entry on dynamic table in adf 11 .6

    Hi All,   JDev version 11.6   I have a usecase based on dynamic VO. How to restrict the decimal numbers on table columns . When user enter the decimal number .I have to show error message.   In order to achieve above requirement .I have added value c

  • Having a bit of a nightmare with this laptop i have bought

    Hey, so i bought a second hand macbook pro 15 inch 2009 yesterday, it is to act as a sister computer to my imac for producing music on The guy who sold it to me sold me it with mountain lion on and final cut and some other programmes, however i didn'

  • Issues with New PFCG role

    Hi Experts, I have created a new Business role ZBP_MKT_MAN and PFCG role ZSAP_CRM_UIU_MKT_PROFESSIONAL. However the authorisations are not getting copied from SAP_CRM_UIU_MKT_PROFESSIONAL to ZSAP_CRM_UIU_MKT_PROFESSIONAL properly. Can someone guide m

  • Upate 2nd date field in the same table.

    This is probably a simple fix, but i can't seem to get it. Any help is greatly appreciated! I need to update a field (ACC_DATE2) in the table called (DRIVERS_ACCIDENTS) and insert a formatted (ACC_DATE) field in the format [mm//dd/yyyy] Here is what

  • Problem Opening Hyperlink on Adobe .pdf Docs Using Safari Browser

    Does anyone have a problem opening a hyperlink on .pdf documents using Safari browser on iPhone or Mac computers?