APEX report sorting makes report slow

Hi,
I have some reports in APEX that are fast (3 sec) when I have no sorting enabled and they turn slow (20 sec) when I enable column sorting.
The reports are based on data running over a DB-link, all tables come from the same DB-link. When I launch the queries (with filled in parameters) in SQL+ then it takes no more then 5 sec (with or without sorting). The result is about 1000 to 2000 records (only showing 25 in the report with pagination).
How can I make the report fast (less then 5 sec) with sorting enabled?
Is there any known bug in APEX that is the source of my problem?
Thanks in advance.

Good point, but I already have recreated the report (delete and recreate) with no result. Cause I know that sometimes the reports run slow, cause they are somehow confused with the sorting, and in most cases it helps to recreate the report (which resets the report ID, so that it's like clearing the user preferences).
First I thougt it had to do something with the user preferences, but I think that it is something different.
I really don't know how to explain the time difference between SQL+ and APEX.

Similar Messages

  • Apex report performance is very poor with apex_item.checkbox row selector.

    Hi,
    I'm working on a report that includes some functionality to be able to select multiple records for further processing.
    The report is based on a view that contains a couple of hundred thousand records.
    When i make a selection from this view in sqlplus , the performance is acceptable but the apex report based on the same view performes very poorly.
    I've noticed that when i omit the apex_item.checkbox from my report query, performance is on par with sqlplus. (factor 10 or so quicker).
    Explain plan appears to be the same with or without checkbox function in the select.
    My query is:
    select apex_item.checkbox(1,tan_id) Select ,
    brt_id
    , tan_id
    , message_id
    , conversation_id
    , action
    , to_acn_code
    , information
    , brt_created
    , tan_created
    from (SELECT brt.id brt_id, -- view query
    MAX (TAN.id) tan_id,
    brt.message_id,
    brt.conversation_id,
    brt.action,
    TAN.to_acn_code,
    TAN.information,
    brt.created brt_created,
    TAN.created tan_created
    FROM (SELECT brt_id, id, to_acn_code, information, created
    FROM xxcjib_transactions
    WHERE tan_type = 'DELIVER' AND status = 'FINISHED') TAN,
    xxcjib_berichten brt
    WHERE brt.id = TAN.brt_id
    GROUP BY brt.id,
    brt.message_id,
    brt.conversation_id,
    brt.action,
    TAN.to_acn_code,
    TAN.information,
    brt.created,
    TAN.created)
    What could be the reason for the poor performance of the apex report?
    And is there another way to select multiple report records without the apex_item.checkbox function?
    I'm using apex 3.2 on oracle 10g database.
    Thanks,
    Niels Ingen Housz
    Edited by: user11986529 on 19-mrt-2010 4:06

    Thanks for your reply.
    Unfortunately changing the pagination doesnt make much of a difference in this case.
    Without the checkbox the query takes 2 seconds.
    With checkbox it takes well over 30 seconds.
    The second report region on this page based on another view seems to perform reasonably well with or without the checkbox.
    It has about the same number of records but with a different view query.
    There are also a couple of filter items in the where clause of the report queries (same for both reports) based on date and acn_code and both reports have a selectlist item displayed in their regions based on a simple lov. These filter items don't seem to be of influence on the performance.
    I have also recreated the report on a seperate page without any other page items or where clause and the same thing occurs.
    With the checkbox its very very slow (more like 20 times slower).
    Without it , the report performs well.
    And another thing, when i run the page with debug on i don't see the actual report query:
    0.08: show report
    0.08: determine column headings
    0.08: activate sort
    0.08: parse query as: APEX_CMA_ONT
    0.09: print column headings
    0.09: rows loop: 30 row(s)
    and then the region is displayed.
    I am using databaselinks in the views b.t.w
    Edited by: user11986529 on 19-mrt-2010 7:11

  • Page breaks in (html) printed apex report

    I am having a strange problem that appears to be related to APEX page template.
    I have a report that is html generated by a PL/SQL function. I need to have page breaks in the printed report at specific locations. I am adding this style to the html output of the function:
    <STYLE>
    DIV.pageBreak { page-break-before: always; }
    </STYLE>
    and I insert this at the locations I need breaks:
    < D I V CLASS="pageBreak"/>
    (without the spaces in DIV)
    (found this technique here: http://www.unagibay.com/DesktopDefault.aspx?tabindex=1&tabid=100&itemid=1821 )
    This works perfect when I run the report in IE, but FireFox is "ignoring" the page breaks. However, if I take just the output of the PL/SQL function in an html doc, FireFox works fine (breaks at the proper places). This makes me believe something related to the "page wrapper" content generated by APEX causes FireFox to not handle the breaks.
    I have tried copying and editing the Popup and Printer Friendly page templates, but I either remove too much and the page doesn't render, or the page breaks don't work.
    My questions for the APEX gurus are:
    1. Is there an "approved" way to get page breaks in the printed version of an APEX report, or is there a better way to do what I need to do.
    2. What is the minimum contents for a page template (what can I safely remove).
    Thanks,
    Bill

    Hi Owen,
    the page breaks are inserted before/after the section.  Expand the report structure window and make sure that the properties window is open below.  Once you click on the section part, you will see where you can insert the page breaks - the check boxes will appear in the properties.
    yes on the second part - just insert the page break between the data providers and then repeat the header for the data provider on the pages (also check boxes on the properties tab)
    Good luck

  • Duplicate Entries in APEX Report

    Hello everyone,
    I'm generating an APEX report that selects records and the user assigned to them. The records are all unique in the main table, but I have to link 4 different tables together to get all the information I need. In one of the tables, there are many different entries referencing the same CallID. This is causing my report to display all of those entries, even though they are duplicates on the report. Is there a way to make that column in the table unique, or prevent the entries from appearing multiple times?
    I've tried using the Group By statement, but I get this error "ORA-00979: not a GROUP BY expression".
    Thanks.

    Hi,
    It would depend on what data you actually want to end up with. If the information in each record on the final table is unique apart from the CallID value, then you will end up with "duplicates" of the data in the other three tables. If you think of a simplified version of this, you have a parent/child relationship between the tables - looking at things from the child table's point of view, several child records may have the same parent. Therefore, if you create a report that includes ALL details from ALL tables, then you will see the parent's information displayed for each child.
    So, if you only want to see one parent's information regardless of the number of child records you have, you either have to combine the child records into a single value or use the Apex report's "Break Formatting" functionality (shown at the bottom of the report's Report Attributes tab). Using the GROUP BY within the SQL statement would normally require you to use an aggregation function to return a single value from the child table - for example, MAX(), MIN(), SUM(), COUNT() etc. If you didn't want to aggregate data, you could use DISTINCT instead (as in SELECT DISTINCT fieldlist FROM tables) but this will only remove duplicate records where ALL values in ALL columns matched.
    So, it does depend on the data itself and how you want to display it.
    Andy

  • Stored Procedure used as a data source for an Apex report

    Just wondering whether anyone has used a Stored Procedure as the data source for an Apex report. An option to select Stored Procedures(s) as the data source does not appear within the IDE (only displays Table, Views, Functions).
    Do you have to return the definition of the Stored Procedure via a function ... if so, how is this done ?
    Thank you.

    >
    Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "920338".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    Just wondering whether anyone has used a Stored Procedure as the data source for an Apex report. An option to select Stored Procedures(s) as the data source does not appear within the IDE (only displays Table, Views, Functions).
    Do you have to return the definition of the Stored Procedure via a function ... if so, how is this done ? When asking a question about "reports" it's firstly essential to differentiate between standard and interactive reports. Standard reports can be based on tables, views, SQL queries, or PL/SQL function blocks that return the text of a SQL query. Interactive reports can only be based on a SQL query.
    "Stored Procedures" are therefore not an option (unless you are using the term loosely to describe any PL/SQL program unit located in the database, thus including functions). What would a procedure used as the source of a report actually do? Hypothetically, by what mechanisms would the procedure (a) capture/select/generate data; and (b) make this data available for use in an APEX report? Why do you want to base a report on a procedure?

  • ORA-01858 error from Apex Report on working/valid underlying query

    After two days of searching these forums and AskTom, I think I need to post the following problem.
    I have what seems to be a valid view of some data created as follows (with an apology for the formatting - doesn't seem to be a way of using a fixed font here):
    CREATE OR REPLACE FORCE VIEW "PRICING_CAPABILITY"."POW_EXEC_SUMM010" ("Item",
    "Jul-09", "Aug-09", "Sep-09", "Oct-09", "Nov-09", "Dec-09", "Jan-10",
    "Feb-10", "Mar-10", "Apr-10", "May-10", "Jun-10", "YTD")
    AS
    SELECT
    "Item",
    SUM(DECODE("ItemMonth",'Jul-09',"ItemValue",0)) "Jul-09",
    SUM(DECODE("ItemMonth",'Aug-09',"ItemValue",0)) "Aug-09",
    SUM(DECODE("ItemMonth",'Sep-09',"ItemValue",0)) "Sep-09",
    SUM(DECODE("ItemMonth",'Oct-09',"ItemValue",0)) "Oct-09",
    SUM(DECODE("ItemMonth",'Nov-09',"ItemValue",0)) "Nov-09",
    SUM(DECODE("ItemMonth",'Dec-09',"ItemValue",0)) "Dec-09",
    SUM(DECODE("ItemMonth",'Jan-10',"ItemValue",0)) "Jan-10",
    SUM(DECODE("ItemMonth",'Feb-10',"ItemValue",0)) "Feb-10",
    SUM(DECODE("ItemMonth",'Mar-10',"ItemValue",0)) "Mar-10",
    SUM(DECODE("ItemMonth",'Apr-10',"ItemValue",0)) "Apr-10",
    SUM(DECODE("ItemMonth",'May-10',"ItemValue",0)) "May-10",
    SUM(DECODE("ItemMonth",'Jun-10',"ItemValue",0)) "Jun-10",
    SUM("ItemValue") AS "YTD"
    FROM
    SELECT
    'New Proposals Received' AS "Item",
    TO_CHAR(t1.scope_received,'Mon-RR') AS "ItemMonth",
    COUNT(*) AS "ItemValue",
    10 AS "SortOrder"
    FROM
    PRICING_CAPABILITY.POW_DATA t1
    WHERE
    t1.scope_received IS NOT NULL
    AND extract(YEAR FROM t1.scope_received) IN (2009,2010)
    AND t1.scope_received >= '01-JUL-2009'
    GROUP BY
    'New Proposals Received',
    TO_CHAR(t1.scope_received,'Mon-RR'),
    10
    UNION
    SELECT
    'New Proposals Completed' AS "Item",
    TO_CHAR(t2.pricing_approval,'Mon-RR') AS "ItemMonth",
    COUNT(*) AS "ItemValue",
    20 AS "SortOrder"
    FROM
    PRICING_CAPABILITY.POW_DATA t1
    JOIN PRICING_CAPABILITY.POW_LAST_HISTORY t2
    ON
    t1.POW_DATA_ID = t2.POW_DATA_ID
    WHERE
    t2.pricing_approval IS NOT NULL
    AND extract(YEAR FROM t2.pricing_approval) IN (2009,2010)
    AND t2.pricing_approval >= '01-JUL-2009'
    GROUP BY
    'New Proposals Completed',
    TO_CHAR(t2.pricing_approval,'Mon-RR')
    GROUP BY
    "Item",
    "SortOrder"
    ORDER BY
    "SortOrder" ;
    This view works, ie produces the right results when run (ie select * from ...) in SQL Developer and in the SQL Workshop section of Apex.
    But when I attempt to produce an Apex report using it as the source of data, I get the following error:
    ORA-01858: a non-numeric character was found where a numeric was expected
    The error is displayed before any part of the report itself is displayed, ie the Region Header is displayed and then the error message.
    So far, anything I've been able to find on the forums or AskTom suggests that it is probably due to a date conversion problem. But the aim here is to summarise dated records by month, so I'm extracted the year and month elements of the date values, converting them to strings (using TO_CHAR), and then using the resulting 'Mon-YY' strings to group the results.
    If there is a better way, I'm interested.
    But I don't understand why Apex seems to be rejecting what appear to be valid results from a valid working query.
    Any ideas? Suggestions?
    Cheers,
    Peter

    Thanks again, Flavio. I'm learning and I appreciate your patience.
    The solution you provided is very similar to the one I came up with after your previous message, but I didn't have the NLS_DATE_LANGUAGE parameter. I'll go back and try it.
    I appreciate your explanation re Apex not needing to know and Oracle assuming that the client knows what it is doing, but it puzzles me more.
    The way that I originally had things, I think, was consistent with what you have explained, but it didn't work. To make it clear:
    1 I had an Oracle view that had no parameters and contained the date literal in the where clause and worked fine in both SQL Developer and in the Apex SQL Workshop.
    2 The view did not return any date values. Aside from the column headings and the first column (of character strings), the body of the table comprised integer values only.
    3 So, when Apex called the view, I would have expected the Oracle server to independently execute the view and return the (dateless) results to Apex, which would then present the unmodified results in a standard report. This is, I think, what SQL Developer and the Apex SQL Workshop appear to have successfully done.
    My expectation seems to be consistent with at least some of your explanation (ie [Oracle assumes] "+that the client knows what it is doing+" and "+apex doesn't need to know anything about the underlying query+"), but is not consistent with actual experience, where Apex seems to know that the underlying query contains a date literal and unsuccessfully (and unnecessarily) attempts to interpret it.
    I'm obviously missing something about how Apex and Oracle interact in this situation. While I don't need to know - as I have a working solution now - it is valuable to understand how things work. Makes life easier and more productive.
    Cheers,
    Peter

  • Regarding Apex Report

    Hi all
    Anyone know how to compose a well-formatted form and report in APEX? Currently we are using ACCESS and SQL Server Reporting service to make formatted report (User can print them out, fill in and archive then), but I haven't found any in APEX. I know creating a page as HTML may be one of the solution but we have to customize it with a huge effort. Is there any other express way of doing this?
    Thanks
    Daniel

    Have you tried using the PDF Printing option for the apex reports? Search this forum on pdf printing. There are also some other options for a more professional layout.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------

  • APEX Report to balance a column of data over 3 columns

    I have an sql report that outputs a code and description e.g.
    1  Ape
    2  Boar
    3  Cat
    4  Dog
    5  Elephant
    6  Goat
    7  Hare
    8  Ibis
    9  Jackel
    10 Kangaroo
    11 Lion
    12 Mouse
    13 Numbat
    I need the following output where the number of records can change but I always want the values to fit into 3 evenly balanced columns e.g. Sorry about trying to line the columns up
    1  Ape      6  Goat    11  Lion
    2  Boar      7  Hare    12  Mouse
    3  Cat      8  Ibis    13  Numbat
    4  Dog      9  Jackel    
    5  Elephant      10  Kangaroo    
    What is the best way to do this in one APEX report. I've tried using 3 separate reports in columns 1,2,3 side by side with "no template" but I can't seem to centre the 3 reports and spread out the values evenly across the page.
    thanks in advance
    Paul P

    Interesting data.
    See:
    {thread:id=414418}
    {thread:id=1013063}
    {thread:id=1011638}

  • Is there any way to sent apex reports in mail

    Hi All,
    I have a requirement to sent an apex report as a mail. Is it possible? Or will I have to write PLSQL procedure to collect the records and embed in html tags and then send the mail
    I tried to use &lt;iframe&gt; tag and embed the apex page which is public in to the mail, But it doesn't look good.
    Thanks & Regards,
    Vikas Krishna

    Vikas,
    As I understand it, this will be a feature of 4.0. However, for now you must still create them manually. Using public pages, as you've seen, can be tricky. Think about pagination and such.
    If an iframe would have "worked" then why not an email with a link back to the right page?
    Regards,
    Dan
    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
    http://sourceforge.net/projects/plrecur
    You can reward this reply by marking it as either Helpful or Correct ;-)

  • Re: Problem providing download link for BLOB data in apex report

    Hi Don,
    Your solution below worked but in the download option i only see save but not open for PDf file in the blob. Please let me know if you have any suggestion to achieve it
    Thanks
    Jo
    Problem providing download link for BLOB data in apex report 
    591953 Nov 19, 2008 1:55 PM (in response to 660436)
    Currently Being Moderated
    Good morning,
    Here is how I have solved this problem.
    1. The select statement in the sql for the report should not include the BLOB column. I decided to select only 2 columns, the column that has the key and the column with the filename.
    2. On the first column ( the primary key ) I put in the format statement that was simply DOWNLOAD:TABLENAME:BLOB_COLUMN:PRIMARY_KEY
    This works. I believe that the Oracle error I was getting was because I was trying to apply this format statement to the actual BLOB column.
    So, it appears that you can use any of the columns in the report to hold the DOWNLOAD format statement since in the format statement, you are defining the BLOB table, BLOB column and the primary key into that column.
    Hope this helps,
    Don.

    Branched out from a years old thread.
    user3003326 Don't post to old threads, please.

  • How to fetch data to APEX Report using stored procedure?

    hi all,
    i am making a report in APEX. user selects two dates and clicks GO button - i have a Stored Procedure linked to that result region so Stored Procedure gets called.
    my stored procedure does the following -
    using specified dates (IN) i do query and put data into a table (this table has been created only for this report) -
    i want to show all these data i entered into the table on my APEX report in the same procedure call. can i use ref cursor to return? how to do that?
    currently, i use another button in APEX which basically fetches all data from table. basically, user clicks one button to generate report and then another button to get report. which is not desirable at all :(
    i m using APEX      3.1.2.00.02 and Oracle 10 database.
    pls let me know if you need further clarification of the problem. thanks in advance.
    regards,
    probashi
    Edited by: porobashi on May 19, 2009 2:53 PM

    Thanks Tony.
    I am not sure what you meant by >> change the report to be based off of a query returning sql statement, no need to keep that table around.... >>
    Here's my stored procedure
    create or replace
    PROCEDURE ABC_PROC (
    START_DATE IN DATE,
    END_DATE IN DATE
    AS
    RULE_REC MTG_OFFICER_FORECAST%ROWTYPE;
    TYPE REF_CURSOR IS REF CURSOR;
    TCUR REF_CURSOR;
    BEGIN
    DELETE FROM ABC_REPORT;
    OPEN TCUR FOR
    SELECT ABC_FORECAST.*
    from MTG_OFFICER_FORECAST , MTG_USERS
    WHERE MTG_OFFICER_FORECAST.NBR_OFFICER = MTG_USERS.NBR_OFFICER AND
    MTG_OFFICER_FORECAST.NBR_INSTITUTION = MTG_USERS.NBR_INSTITUTION;
    LOOP
    FETCH TCUR INTO RULE_REC;
    EXIT WHEN TCUR%NOTFOUND;
    INSERT INTO ABC_REPORT( NBR_OFFICER, OFFICER_NAME, FORECAST_NBR_LOANS, FORECAST_LOAN_AMT, FORECAST_FEES,
    ACTUAL_NBR_LOANS, ACTUAL_LOAN_AMT, ACTUAL_FEES, RATIO_NBR_LOANS, RATIO_LOAN_AMT, RATIO_FEES, NBR_INSTITUTE )
    VALUES ( RULE_REC.NBR_OFFICER, RULE_REC.NAME_LOAN_OFFICER, RULE_REC.NBR_LOANS, RULE_REC.AMT_LOAN, RULE_REC.AMT_FEES,
    ACTUAL_NBR_LOANS, ACTUAL_LOAN_AMOUNT, ACTUAL_FEES, SUCCESS_RATIOS_NBR_LOANS_PERC, SUCCESS_RATIOS_LOAN_AMT_PERC, SUCCESS_RATIOS_FEES_PERC, RULE_REC.NBR_INSTITUTION );
    END LOOP;
    CLOSE TCUR;
    END ABC_PROC;
    Thanks,
    Probashi
    Edited by: porobashi on Jun 2, 2009 11:43 AM

  • APEX Report Data Download in Excel and PDF format

    Hi,
    Can someone please guide me how to download APEX report data in Excel and PDF format.I know this is possible through BI Publisher but that is extra Licence cost for client so i don't want to use that option.
    Thanks in advance.
    Regards
    Prabhat Mishra

    1005844 wrote:
    Hi ,
    Thanks for Reply,
    I am using APEX 4.2 but when i am trying to download the IR data then getting 3 options only(CSV,HTML and Email).
    PrabhatWell, Excel should understand the .csv format for offloads. Perform web seraches to see what can be done for pdfs

  • Query of the complicated rdf-report in apex-report

    I try to migrate rather complicated rdf report into Apex. I have sucesfully converted the reports file xx.rdf into:
    1. xx.xdo file
    2. xx.rtf word file
    3. xx.xml data file
    4. xx_S.pls and xx_B.pls as package files in database
    The converted xx.rtf file is OK with all fields and images in right places In the Word I get a beautiful xx.pdf report when I start the preview using converted xx.xml file as the data file. -- The problem is just the package file with its several functions. The xml file has also many levels of data formed by tags like <list_g> etc.. Many of Word fields are CF fields from reports (xx.rdf) which now are as package functions with the same names.
    Is there any direct way to generate the Apex report query whic form the xml data file? It seems impossible to start create an Apex query from the package functions and trying to embed on it all the same fields as in xml file. Is it possible to somehow use xx.xdo file and bi publisher as help.
    Thank you very much.

    Okay, there is some confusion there.. You said: "In our case the customer is not willing to invest into Oracle Reports", Yet you are converting an Oracle Report file for their application, is this NOT their report file?
    Then you said " Also the customer is not very eager to use its BI Publisher for Apex reports " But APEX WILL be using BI Publisher for the PDF generation of the report, do they understand having Bi Publisher running the report that APEX can get the PDF from Bi Publsiher?
    Sounds like the customer is rather snarky on their requirements..
    Thank you,
    Tony Miller
    Webster, TX

  • Column Links in Apex Reports

    I am using version 4.0 of APEX.  My question concerns linking to other APEX pages from a report.  In APEX we link to another page, which may be a form or another report, by using a column in the report as a link column.  Any column may be used to transfer values from any other column.  This works fine, but the disadvantage is that whichever column is used as the link column has a heading which identifies the column's purpose but may not identify the purpose of the transition to another page.  In Oracle Forms, we could use buttons as a column of the multi-row screen (i.e. same as APEX report), and the button's label identified the purpose for the transition.
    Is there any way to create a column in an APEX report  to serve the same purpose as the button in Oracle Forms?

    Doug wrote:
    I am using version 4.0 of APEX.  My question concerns linking to other APEX pages from a report.  In APEX we link to another page, which may be a form or another report, by using a column in the report as a link column.  Any column may be used to transfer values from any other column.  This works fine, but the disadvantage is that whichever column is used as the link column has a heading which identifies the column's purpose but may not identify the purpose of the transition to another page.  In Oracle Forms, we could use buttons as a column of the multi-row screen (i.e. same as APEX report), and the button's label identified the purpose for the transition.
    Is there any way to create a column in an APEX report  to serve the same purpose as the button in Oracle Forms?
    When discussing "reports" it is essential to indicate whether this means a standard report or an interactive report in order to receive an appropriate response.
    It is possible to create a link column that is distinct from report data columns. In standard reports, this is done using the Add Column Link option from the Tasks menu in the right sidebar of the Report Attributes page. In interactive reports, define a Link Column on the Report Attributes page.
    To provide further information about links to users in both cases, specify an HTML title attribute for the link in the Link Attributes property of the link definition. This will be rendered as a tooltip when the cursor hovers over the link in visual browsers, and as an audio cue on navigation to the link when using a screen reader.

  • How to do outer join select query for an APEX report

    Hello everyone,
    I am Ann.
    I have one select statement that calculate the statistics for one month(October 2012 in this example)
    select ph.phase_number
    , sum ( (case
    WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE('Oct 2012','MON YYYY'))
    THEN last_day(TO_DATE('Oct 2012','MON YYYY'))
    ELSE ph.date_finished
    END )
    - ph.date_started + 1) / count(def.def_id) as avg_days
    from phase_membership ph
    inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
    inner join defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY'))
    and ph.active = 1
    and UPPER(ce.court_name) LIKE '%'
    group by rollup(phase_number)
    Result is as below
    Phase_Number     AVG_DAYS
    Phase One     8.6666666666666667
    Phase Two     14.6
    Phase Three     12
         11.4615365
    I have other select list mainly list the months between two date value.
    select to_char(which_month, 'MON YYYY') as display_month
    from (
    select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
    from all_objects
    where
    rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
    order by which_month )
    Query result is as below
    DISPLAY_MONTH
    AUG 2012
    SEP 2012
    OCT 2012
    Is there any way that I can join these two select statement above to generate a result like:
    Month          Phase Number     Avg days
    Aug 2012     Phase One     8.666
    Sep 2012     Phase One     7.66
    Oct 2012     Phase One     5.66
    Aug 2012     Phase Two     8.666
    Sep 2012     Phase Two     7.66
    Oct 2012     Phase Two     5.66
    Aug 2012     Phase Three     8.666
    Sep 2012     Phase Three     7.66
    Oct 2012     Phase Three     5.66
    Or
    Month          Phase Number     Avg days
    Aug 2012     Phase One     8.666
    Aug 2012     Phase Two     7.66
    Aug 2012     Phase Three     5.66
    Sep 2012     Phase One     8.666
    Sep 2012     Phase Two     7.66
    Sep 2012     Phase Three     5.66
    Oct 2012     Phase One     8.666
    Oct 2012     Phase Two     7.66
    Oct 2012     Phase Three     5.66
    And it can be order by either Phase Number or Month.
    My other colleague suggest I should use an left outer join but after trying so many ways, I am still stuck.
    One of the select I tried is
    select a.display_month,b.* from (
    select to_char(which_month, 'MON YYYY') as display_month
    from (
    select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
    from all_objects
    where
    rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
    order by which_month )) a left outer join
    ( select to_char(ph.date_finished,'MON YYYY') as join_month, ph.phase_number
    , sum ( (case
    WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(a.display_month,'MON YYYY'))
    THEN last_day(TO_DATE(a.display_month,'MON YYYY'))
    ELSE ph.date_finished
    END )
    - ph.date_started + 1) / count(def.def_id) as avg_days
    from phase_membership ph
    inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
    inner join defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started <= last_day(TO_DATE(a.display_month,'MON YYYY'))
    and ph.active = 1
    and UPPER(ce.court_name) LIKE '%'
    group by to_char(ph.date_finished,'MON YYYY') , rollup(phase_number)) b
    on a.display_month = b.join_month
    but then I get an error
    SQL Error: ORA-00904: "A"."DISPLAY_MONTH": invalid identifier
    I need to display a report on APEX with option for people to download at least CSV format.
    I already have 1 inteactive report in the page, so don’t think can add another interactive report without using the iframe trick.
    If any of you have any ideas, please help.
    Thanks a lot.
    Ann

    First of all, a huge thanks for following this Frank.
    I have just started working here, I think the Oracle version is 11g, but not sure.
    To run Oracle APEX version 4, I think they must have at least 10g R2.
    This report is a bit challenging for me.I has never worked with PARTITION before.
    About the select query you suggested, I run , and it seems working fine, but if I try this,
    it return error ORA-01843: not a valid month
    DEFINE startmonth = "Aug 2012";
    DEFINE endmonth   = "Oct 2012";
    WITH     all_months     AS
         select add_months(to_date('&startmonth','MON YYYY'), rownum-1) AS which_month
         ,      add_months(to_date('&startmonth','MON YYYY'), rownum  ) AS next_month
         from all_objects
         where
         rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
    select TO_CHAR (am.which_month, 'Mon YYYY')     AS month
    ,      ph.phase_number
    , sum ( (case
    WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(am.which_month,'MON YYYY'))
    THEN last_day(TO_DATE(am.which_month,'MON YYYY'))
    ELSE ph.date_finished
    END )
    - ph.date_started + 1) / count(def.def_id) as avg_days
    FROM           all_months          am
    LEFT OUTER JOIN  phase_membership  ph  PARTITION BY (ph.phase_number)
                                        ON  am.which_month <= ph.date_started
                               AND am.next_month  >  ph.date_started
                               AND ph.date_started <= last_day(TO_DATE(am.which_month,'MON YYYY'))  -- May not be needed
                               AND ph.active = 1
    LEFT OUTER join  court_engagement  ce  on  ph.mpm_eng_id = ce.engagement_id
                                        and ce.court_name IS NOT NULL  -- or something involving LIKE
    LEFT OUTER join  defendant         def on  ce.defendant_id = def.def_id
                                        AND def.active = 1
    group by rollup(phase_number, am.which_month)
    ORDER BY  am.which_month
    ,            ph.phase_number
    ;Here is the shorted versions of the three tables:
    A_DEFENDANT, A_ENGAGEMENT, A_PHASE_MEMBERSHIP
    CREATE TABLE "A_DEFENDANT"
        "DEF_ID"     NUMBER NOT NULL ENABLE,
        "FIRST_NAME" VARCHAR2(50 BYTE),
        "SURNAME"    VARCHAR2(20 BYTE) NOT NULL ENABLE,
        "DOB" DATE NOT NULL ENABLE,
        "ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
        CONSTRAINT "A_DEFENDANT_PK" PRIMARY KEY ("DEF_ID"))
    Sample Data
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (101,'Joe','Bloggs',to_date('12/12/99','DD/MM/RR'),1);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (102,'John','Smith',to_date('20/05/00','DD/MM/RR'),1);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (103,'Jane','Black',to_date('15/02/98','DD/MM/RR'),1);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (104,'Minnie','Mouse',to_date('13/12/88','DD/MM/RR'),0);
    Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (105,'Daisy','Duck',to_date('05/08/00','DD/MM/RR'),1);
    CREATE TABLE "A_ENGAGEMENT"
        "ENGAGEMENT_ID" NUMBER NOT NULL ENABLE,
        "COURT_NAME"    VARCHAR2(50 BYTE) NOT NULL ENABLE,
        "DATE_REFERRED" DATE,
        "DETERMINATION_HEARING_DATE" DATE,
        "DATE_JOINED_COURT" DATE,
        "DATE_TREATMENT_STARTED" DATE,
        "DATE_TERMINATED" DATE,
        "TERMINATION_TYPE" VARCHAR2(50 BYTE),
        "ACTIVE"           NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
        "DEFENDANT_ID"     NUMBER,
        CONSTRAINT "A_ENGAGEMENT_PK" PRIMARY KEY ("ENGAGEMENT_ID"))
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (1,'AA',to_date('12/08/12','DD/MM/RR'),null,to_date('12/08/12','DD/MM/RR'),null,null,null,1,101);
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (2,'BB',to_date('01/09/12','DD/MM/RR'),null,to_date('02/09/12','DD/MM/RR'),null,null,null,1,102);
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (3,'AA',to_date('02/09/12','DD/MM/RR'),null,to_date('15/09/12','DD/MM/RR'),null,null,null,1,103);
    Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (4,'BB',to_date('01/10/12','DD/MM/RR'),null,to_date('02/10/12','DD/MM/RR'),null,null,null,1,105);
    CREATE TABLE "A_PHASE_MEMBERSHIP"
        "MPM_ID"       NUMBER NOT NULL ENABLE,
        "MPM_ENG_ID"   NUMBER NOT NULL ENABLE,
        "PHASE_NUMBER" VARCHAR2(50 BYTE),
        "DATE_STARTED" DATE NOT NULL ENABLE,
        "DATE_FINISHED" DATE,
        "NOTES"  VARCHAR2(2000 BYTE),
        "ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
        CONSTRAINT "A_PHASE_MEMBERSHIP_PK" PRIMARY KEY ("MPM_ID"))
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (1,1,'PHASE ONE',to_date('15/09/12','DD/MM/RR'),to_date('20/09/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (2,1,'PHASE TWO',to_date('21/09/12','DD/MM/RR'),to_date('29/09/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (3,2,'PHASE ONE',to_date('12/09/12','DD/MM/RR'),null,null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (4,3,'PHASE ONE',to_date('20/09/12','DD/MM/RR'),to_date('01/10/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (5,3,'PHASE TWO',to_date('02/10/12','DD/MM/RR'),to_date('15/10/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (6,4,'PHASE ONE',to_date('03/10/12','DD/MM/RR'),to_date('10/10/12','DD/MM/RR'),null,1);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (7,3,'PHASE THREE',to_date('17/10/12','DD/MM/RR'),null,null,0);
    Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (8,1,'PHASE THREE',to_date('30/09/12','DD/MM/RR'),to_date('16/10/12','DD/MM/RR'),null,1);
    The requirements are:
    The user must be able to request the extract for one or more calendar months, e.g.
    May 2013
    May 2013 – Sep 2013.
    The file must contain a separate row for each calendar month in the requested range. Each row must contain the statistics computed for that calendar month.
    The file must also include a row of totals.
    The user must be able to request the extract for either Waitakere or Auckland or Consolidated (both courts’ statistics accumulated).
    Then the part that I am stuck is
    For each monitoring phase:
    Phase name (e.g. “Phase One”)
    Avg_time_in_phase_all_particip
    for each phase name,
    Add up days in each “phase name” Monitoring Phase, calculated as:
    If Monitoring Phase.Date Finished is NULL or > month end date,
    +(*Month end date* Minus Monitoring Phase.Date Started Plus 1)+
    Otherwise (phase is complete)
    +(Monitoring Phase.Date Finished Minus Monitoring Phase.Date Started Plus 1.)+
    Divide by the numbers of all participants who have engaged in “phase name”.
    This is the words of the Business Analyst,
    I try to do as required but still struggle to identify end_month for the above formula to display for the range of months.
    Of course, I can write two nested cursor. The first one run the list of month, then for each month, run the parameterised report.
    But I prefer if possible just use SQL statements, or at least a PL/SQL but return a query.
    With this way, I can create an APEX report, and use their CSV Extract function.
    Yes, you are right, court_name is one of the selection parameters.
    And the statistics is not exactly for one month. It is kind of trying to identify all phases that are running through the specified month (even phase.date_started is before the month start).
    This is the reason why I put the condition AND ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY')) (otherwise I get negative avg_days)
    User can choose either one court "AA" or "BB" or combined which is all figures.
    Sorry for bombarding you a lot of information.
    Thanks a lot, again.
    Edited by: Ann586341 on Oct 29, 2012 9:57 PM
    Edited by: Ann586341 on Oct 29, 2012 9:59 PM

  • Calling a .rdf report from a link on a apex report column

    Hi,
    I want to call a xxx.rdf report from a link on a apex report column.
    Can anyone help me on this ?
    Best regards,
    JCN

    Hi,
    Sorry - I should have read a bit further in your last post!
    The url variable that you're defining should just be the URL string that you want to create, so you only need the "http://........" part. There's also a + missing after the "&TODT..." string.
    The "DEA_PERMIT_ID=&G_PERMIT_ID." part at the end should have an & at the start to indicate a new parameter in the URL. Otherwise, &G_PERMIT_ID. would be replaced by the value stored in the session for the G_PERMIT_ID item (presumably that is an Application Item?).
    So:
    function callPopup()
    var url = "'http://snapper.accsp.org/reports/rwservlet?destype=cache&desformat=PDF&report=edr_landings_dollars_by_vessel.rdf&userid=evtr_report/chicken99@safis&FROMDT=" + $v("P810_FROM") + "&TODT=" + $v("P810_TO") + "&DEA_PERMIT_ID=&G_PERMIT_ID.";
    popupURL(url);
    }Andy

Maybe you are looking for

  • TS5275 Garageband(10.0.2) Cant purchase the complete set of content! Apple store just will not let me do it plz help! tried almost everything... really want it!

    Please help me with dat! After putting my password in in the apple store the page just goes blank. tried to reboot the computer and all other kinds of things! i got enough money on my account to purchase it as well. got no idea why it doesn't work pr

  • Upgrade IDS (4.1- 5.1)

    How to upgrade my IDS 4215 from v4.1 to v5.1? Does my ciscowork be upgraded at same time? Thanks

  • Read data from spreadsheet

    Hi NI Community,  I'm trying to read data from a .csv file (saved from Excel) in LabVIEW 2013 and cannot understand why I keep getting the same error.  I am using the "Read From Spreadsheet File" VI to accomplish this.  I need to read in the data and

  • Select option value dynamic

    Hi, I have a select option which must have a default value. This default value is the current date -1 (yesterday...). DATA ws_date TYPE p0001-begda. SELECT-OPTIONS s_date FOR ws_date DEFAULT sy-datum - 1. But sy-datum - 1doesn't exist. The 'RP_CALC_D

  • Execute txkWfClone.sh in a shell script

    We have a requirement that needs txkWfClone.sh to run inside a shell script (unix). We need to pass the username/password in the shell script. Basically we need to run this as a silent process. Any suggestions on how to accomplish that?