Report Query Problem/Question

I have 3 tables:
Table one - Recipe
PK varchar2(100) (yes, I know it isn't a number, but I had to put a 'CPL' in front of each sequence)
RECIPE_NAME varchar2(250)
Table two - Ingredients
PK varchar2(100) (same reason as above expect needed a 'P' in front of each sequence)
INGREDIENT_NAME varchar2(250)
PRICE number
Table three - Lkup_recipes
PK number
RECIPE_PK varchar2(100)
INGREDIENT_PK varchar2(100)
QUANTITY
So, table one contains data like this:
CPL1234 'APPLE PIE'
CPL1256 'PIE CRUST'
table two contains data like this:
P1234 'FLOUR' 5.00
P1256 'EGG' 2.56
P1278 'WATER' 0.00
P1312 'APPLE' 0.50
table three contains data like this:
1234 CPL1234 CPL1256 2
1235 CPL1234 P1312 5
1236 CPL1234 P1234 1
1237 CPL1256 P1234 1
1238 CPL1256 P1278 3
Now, I have a report that shows the RECIPES with their price. I am having problems getting the proper price, based on the data above, since my recipe, Apple Pie, contains ingredients as well as the recipe, Pie Crust.
I would expect the price of my pie to be: $17.50 but I am only getting a cost of $7.50.
The query I am currently using is:
select t1.pk, t1.recipe_name, sum(t2.price * t3.quantity) Price
from recipe t1, ingredients t2, lkup_recipe t3
where t1.pk = t3.recipe_pk
and t2.pk = t3.ingredient_pk
group by t1.pk, t1.recipe_name
Obviously it isn't tracking down beyond the recipe, Pie Crust, to determine its' cost based on the ingredients contained in it.
Any ideas out there on how to get my full price?
Thanks!!
Chrissy

Hi Chrissy, <br>
Your problem is that while you put "Pie Crust" as an ingredient in the apple pie, It is not also in the ingredients table. Heres an option:<br>
run a batch job that looks at the ingredients table and finds all of the ingredients that are actually recipes. Have it calculate the cost of these "sub recipes" and insert them in the ingredients table along with their cost. <br><br>
While this will get you around your problem, I dont think it is a good solution. You should rework your data model to be more versatile to include sub recipes OR you can simply alter your application to not use sub-recipes at all (instead just re-list all of the ingredients).
<br><br>
Let me know if you need any advice.
<br>
Dave<br>
Lehr.ServeHTTP.com

Similar Messages

  • Printable Report Query Problem

    I am attempting to develop a printable report query. I have created a report query under shared components that consists of 12 separate queries that gather data that all relates to a single page item. The intent is to create a printed PDF document for the user on demand that will display all this information about the page item that they have selected.
    The report query gathers the information and generates an XML file in the following format.
    <DOCUMENT>
        <ROWSET1>
            <ROWSET1_ROW>
                             *Data from query 1*
            </ROWSET1_ROW>
        </ROWSET1> 
        <ROWSET2>
            <ROWSET2_ROW>
                              *Data from query 2*
            </ROWSET2_ROW>
            <ROWSET2_ROW>
                              * Data from query 2*
            </ROWSET2_ROW>
       </ROWSET2>
       <ROWSET3>
           <ROWSET3_ROW>
                              * Data from query 3*
           </ROWSET3_ROW>
           <ROWSET3_ROW>
                              * Data from query 3*
           </ROWSET3_ROW>
       </ROWSET3>
    </DOCUMENT>I then took this XML file and developed an RTF template using BI Publisher desktop and imported it as a Report Layout.
    I then connected this RTF layout to the report query and ran it. I did not get the all the data to print.
    I found the reason it did not work was that the XML file that is generated from the report query is not static. The next XML file that was generated from the report query looked like this:
    <DOCUMENT>
        <ROWSET1>
            <ROWSET1_ROW>
                               * Data from query 3*
            </ROWSET1_ROW>
            <ROWSET1_ROW>
                               * Data from query 3*
            </ROWSET1_ROW>
        </ROWSET1> 
        <ROWSET2>
            <ROWSET2_ROW>
                               * Data from query 7*
            </ROWSET2_ROW>
            <ROWSET2_ROW>
                               * Data from query 7*
            </ROWSET2_ROW>
            <ROWSET2_ROW>
                               * Data from query 7*
            </ROWSET2_ROW>
       </ROWSET2>
       <ROWSET3>
           <ROWSET3_ROW>
                               * Data from query 1*
           </ROWSET3_ROW>
       </ROWSET3>
    </DOCUMENT>So I cannot develop an RTF template to display the data if I do not know where that data will appear in the generated XML.....
    Questions (I will offer several POINTS to anyone who can answer any of these questions!!!!)
    I am using APEX version 3.1
    *1. Why does the report query seem to randomly renumber and reorder the XML data it produces?*
    *2. Is there any way to make the report query output the XML data in the same order that the individual queries are ordered every time?*
    *3. Is there any way to specifically name the rowsets or rowset rows that is supported by APEX?*
    *4. Are there any other methods that I can explore to produce this report?*
    *5. Is this a problem because I am on an old release? Is this not a problem on 4.1?*
    Edited by: bhenderson on Feb 1, 2012 8:22 AM

    Thanks for your response.
    There are 12 separate queries in the report query. Each one is in a separate box on the report queries screen.
    I don't know how to post an image here, but I will try to describe it:
    The first query selects several fields relating to :P5_WIP_ENTITY_ID, which is a Work order. This query is header information about the job and should only return one row.
    The other queries get other information relating to :P5_WIP_ENTITY_ID, like part numbers that may have been issued to that job, purchases made for that job and so on. These queries may return more than one row or may not return anything.
    I have created the queries in the order that I want them to display on the form, however, when the XML is generated, ROWSET1 may have the data from the Header Query one time, then the next time it may have data from the purchase query. In other words, it does not display the data in the order that the queries appear on the report query page, and it seems to reorder the output at random.
    I have looked everywhere I could think of, but there doesn't seem to be any way of connecting or relating the separate queries. I also tried doing separate queries in one box and joining them, but there is a limit of 60 data items you can select from one query box.
    Edited by: bhenderson on Feb 3, 2012 10:01 AM

  • Out standing MIS Report query problem.

    Hi,
    We designed MIS Report for outstanding mis through Crystal report.here we are facing probleme.ex:AR invoice raised on 01 Jan 09 bill amount 1000 and for this client is received full amount against that bill on 04 march09.in this report we provided parameters for from date and to date. When user selected in parameter from date 010109 to 050309 it will show pending amount is 0.but users are asking if they select from date upto 030309 means it will show pending amount should be show 1000.in this query we are retrieving based on document status when open. How we can show report for this requirements. Please guide me.if we give docstatus='O' or docstatus= 'C' it's showing but pending amount =Bill amount - paid amount here it's showing 0 i think here also we need to pass incoming payment docdate.how wen do please guide me.
    below this is the query.
    set @FromYear=case when month(@ToDate)>=1 and month(@ToDate)<=3 then Year(@ToDate)-1 else Year(@ToDate) end
    set @ToYear=case when month(@ToDate)>=1 and month(@ToDate)<=3 then Year(@ToDate) else Year(@ToDate)+1 end
    --select @fromYear,@toyear,@todate,@ProjCode,@Cardcode,@VoucherType,@GroupName
    select a.u_category,a.docdate,g.name,d.CardCode,d.cardname,e.GroupName,SUBSTRING(CONVERT(VARCHAR(11), a.docdate, 113), 4, 8)as Month of invoiceraised,
    b.seriesname,a.docnum,a.Project,0,a.doctotal,
    paidamount= case when a.paidtodate is NULL then 0 else a.paidtodate end,
    pendingamount= case when isnull(a.doctotal,0)-isnull(a.paidtodate,0) is null then 0 else isnull(a.doctotal,0)-isnull(a.paidtodate,0) end,
    case when year(a.docdate) = @ToYear and month(a.docdate) = 3 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as March ,
    case when year(a.docdate) = @ToYear and month(a.docdate) = 2 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Feb,
    case when year(a.docdate) = @ToYear and month(a.docdate) = 1 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Jan,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 12 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Dec,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 11 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Nov,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 10 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Oct,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 9 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Sept,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 8 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Aug,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 7 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as July,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 6 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as June,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 5 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as May,
    case when year(a.docdate) = @FromYear and month(a.docdate) = 4 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as April,
    --case when a.docdate = (select f_refdate from ofpr where year(f_refdate)=year(a.refdate) then a.doctotal-c.paidtodate else 0 end as Pre-Yr
    nodocsum=isnull(f.nodocsum,0),0 as PreviousFY
    from oinv a
    left join nnm1 b on a.series=b.series
    inner join INV1 c ON a.DocEntry = c.DocEntry
    inner join OCRD d ON d.CardCode=a.CardCode
    left join ocpr g on g.cardcode=d.cardcode
    Inner join OCRG e on e.GroupCode=d.GroupCode and e.grouptype='c'
    LEFT JOIN ORCT f ON a.DocEntry = f.DocEntry
    where
    a.docstatus='O' and
    case when a.doctotal-a.paidtodate is null then 0 else a.doctotal-a.paidtodate end >= 0
    Reds,
    Sampath kumar devunuri.

    Hi,Gordon Du ,
    We are designing through Crystal reports 2008 only. Based on SQL query how we can maintain History of Document status and date in table. Please give me your advise how we can rectify this problem. Kindly find above query.
    Regds,
    Sampath Kumar.

  • Matrix Report Query Problem

    Dear members
    I am using reports 6 and oracle 9i. I am trying to create a matrix report in which i want to show products as rows and dates as columns. Dates should be fixed 7 days any from to dates given by user. I have used two tables prd_plan_m and product_code. I want to show plan_no and plan_qty based on product_code and date. I want to show all the products as rows whether it has plan or not and 7 days columns shows as heading weather in this there is any plan or not.
    For this reason i have made this query.
    SELECT ALL p.code,pkg_prod.get_prod_name(p.code)prod_name,pkg_prod.get_prod_qty(p.code)prod_qty,P.PLAN_ID, P.PLAN_DESC, a.dates,
    P.PLAN_QTY, P.UNIT_ID, P.REMARKS
    FROM PRD_PLAN_M P ,(select rownum - 1 + to_date('20-jul-08', 'dd-mon-rrrr') dates
    from all_objects
    where rownum < to_date('26-jul-08', 'dd-mon-rrrr') -
    to_date('20-jul-08', 'dd-mon-rrrr') + 2)a
    where P.PLAN_DATE(+) = A.DATES
    UNION
    SELECT E.P_CODE,E.PROD_NAME,E.PROD_QTY,null,null,null,null,null,null FROM PROD_CODE E
    But this query shows duplicates rows. suppose one product_code in prd_plan_m has plan_qty shows one row and the row from product_code table also show the same row which have no plan qty.
    Help me in this regard.
    I will be very thankful to you .
    thanks and regards

    Thanks for reply. But this query is also produce the same results see bellow output.
    CODE     PROD_NAME     PROD_QTY     PLAN_ID     PLAN_DESC     DATES     PLAN_QTY UNIT_ID     REMARKS
    0101     MOUNTAIN DEW     225 ML NR               
    0201     PEPSI MAX     240 ML          
    0301     PEPSI          250 ML          P0001L01 TEST PLANE-01     7/21/2008 20000 1          test
    0301     PEPSI          250 ML
    0302     MOUNTAIN DEW     250 ML          P0005L02 NEW ENTRY     7/26/2008 20000          TEST
    0302     MOUNTAIN DEW     250 ML
    Code 0301 and 0302 are repeated. But they should be shown only once. Please help me to resolve this problem.
    thanks & regards

  • XL Reporter Query problem

    I have a query with sbo:
    SELECT T0.DocNum, T0.ItemCode,t0.duedate,T0.PlannedQty, T0.OriginNum as Sale-Order, T0.U_Doc_Remarks,t2.numatcard  FROM OWOR T0 left join OITM T1 ON t0.itemcode = T1.ITEMCODE left join ordr t2 on t0.originnum = t2.docnum where T0.OriginNum = '[%0]'
    but in XL Reporter, How do I set up?  OWOR_OriginNum Equal SO_DocNum and OWOR_OriginNum as a param

    XL Reporter does not support SQL. All its meta data have been predefined in the system. You may not have left join option at all.
    Try some other tools such as Crystal Report or Query PLD.
    Thanks,
    Gordon

  • Performance problem with report query

    Hi,
    I am encountering a performance issue with a page returning a report.
    I have a page that has a region which joins 2 tables. One table has about 220,00 rows, while the other contains roughly 60,000 rows. In the region source of the report region, the query includes join condition with local variables. For example, the page is page 70, and some join conditions are:
    and a.id=:P70_ID
    and a.name like :P70_NAME
    I run the query that returns a large number of rows from sqlplus, and it takes less than 30 sec to complete.
    When I run the page, the report took about 3 minutes to return.
    In this case, :P70_NAME is initialized to '%' on the page.
    I then tried to substitute variable value directly in the query:
    and a.id=1000
    and a.name like '%'
    this time the report returned in about 30 sec.
    I then tried another thing which specified the region as "PL/SQL Function returning sql query", and modified the region as follows:
    l_sql := '.......';
    l_sql := l_sql || 'and a.id=' || v('P70_ID')
    and similar substituting :P70_NAME to v('P70_NAME') and append its value to the l_sql string.
    The report query page also returned in 30 sec.
    Is there any known performance issue with using the bind variable (:PXX_XXX) in the report region?

    If you are able.. flush the shared_pool, run your
    report then query the v$sql_area or v$sql_text tables.
    Or do a google query and look up Cary Milsap's piece on enabling extended trace .. there is your sure fire way of finding the problem sql. I am still learning htmldb but is there a way to alter session enable trace in some pre-query block?

  • Recurring problem - need to touch report query to make page to work again

    Hello
    In my APEX 3.0 (Oracle 10.2.0.3.0) application I have a main menu which is a very simple page with one report that selects from a local table (no dblink) what pages the logged user has access to.
    The problem is that now and then (around once a week) users get "page not found" after they log in to the application but before the main menu is displayed. After some testing I found out that, to fix it, I need to touch the report query (let's say, adding an extra space somewhere) and apply changes. After that, the page works fine...
    I have other much more complex pages in the application that don't have such problem.
    Any advice? Where should I start investigating to fix this?
    Thanks
    Luis
    PS: From the error_log file:
    [Mon Aug 20 10:12:54 2007] [error] [client 10.0.10.87] [ecid: 11877561:10.0.24.16:14092:0:37471,0] mod_plsql: /pls/apex/f HTTP-404 ORA-03113: end-of-file o
    n communication channel\n
    [Mon Aug 20 10:12:54 2007] [alert] [client 10.0.10.87] [ecid: 11877561:10.0.24.16:14092:0:37471,0] mod_plsql: Unable to reset state for mode 0: Err 3114 url=>/pls/apex/f

    i have this exact same problem in our production environment
    i really need help to fix it or we'll lose our major client
    they're fed up with it
    anyone?

  • Problem with Report Query

    I have tested the integration of Apex3.0 and BI Publisher via Report Query.
    This works very well, however I want to create a hierarchical XML document via the following Query:
    select a.id,
    a.persoonsnr,
    a.volgnr_dvb,
    a.jaar,
    a.naam,
    a.code_sagitta,
    a.status,
    a.invgebruiker,
    a.invdatum,
    a.mutgebruiker,
    a.mutdatum,
    cursor (
    select w.afspraken
    from hri_opmwerkresult w) as owr
    from hri_prsactiviteiten a
    I get the error message ORA-00932 inconsistent datatypes expected number got curser
    Is there a work around to create a report-query with master-detail info?

    Anyone?

  • PLEASE report what you've already tried when posting problems/questions!

    A lot of threads have a common theme:
    (1) The first post describes a problem, or asks a question.
    (2) The second (or third, or fourth) post suggests doing or trying something.
    (3) The next response, from the original poster, says "Oh, I already tried that!"
    Please, when describing a problem or asking a question, be reasonably detailed about the scenario, what you did, what results you got, WHAT YOU'VE ALREADY TRIED, etc.
    Vague undetailed problems/questions, not describing the N steps you've already taken to try to resolve it, etc. just waste time and bandwidth all around!
    Doug

    Hi Doug;
    If we are going to start of list of things NOT to do when posting a question, the one I always think is the absolute silliest is when they say I am having trouble with an application and never ever tell up what application they are talking about as if we have a crystal ball which is going to tell us what mythical application it is. Well it turns out generally my crystal ball is foggy just then so I have to ask what are you talking about here.
    Allan

  • Interactive report performance problem over database link - Oracle Gateway

    Hello all;
    This is regarding a thread Interactive report performance problem over database link that was posted by Samo.
    The issue that I am facing is when I use Oracle function like (apex_item.check_box) the query slow down by 45 seconds.
    query like this: (due to sensitivity issue, I can not disclose real table name)
    SELECT apex_item.checkbox(1,b.col3)
    , a.col1
    , a.col2
    FROM table_one a
    , table_two b
    WHERE a.col3 = 12345
    AND a.col4 = 100
    AND b.col5 = a.col5
    table_one and table_two are remote tables (non-oracle) which are connected using Oracle Gateway.
    Now if I run above queries without apex_item.checkbox function the query return or response is less than a second but if I have apex_item.checkbox then the query run more than 30 seconds. I have resolved the issues by creating a collection but it’s not a good practice.
    I would like to get ideas from people how to resolve or speed-up the query?
    Any idea how to use sub-factoring for the above scenario? Or others method (creating view or materialized view are not an option).
    Thank you.
    Shaun S.

    Hi Shaun
    Okay, I have a million questions (could you tell me if both tables are from the same remote source, it looks like they're possibly not?), but let's just try some things first.
    By now you should understand the idea of what I termed 'sub-factoring' in a previous post. This is to do with using the WITH blah AS (SELECT... syntax. Now in most circumstances this 'materialises' the results of the inner select statement. This means that we 'get' the results then do something with them afterwards. It's a handy trick when dealing with remote sites as sometimes you want the remote database to do the work. The reason that I ask you to use the MATERIALIZE hint for testing is just to force this, in 99.99% of cases this can be removed later. Using the WITH statement is also handled differently to inline view like SELECT * FROM (SELECT... but the same result can be mimicked with a NO_MERGE hint.
    Looking at your case I would be interested to see what the explain plan and results would be for something like the following two statements (sorry - you're going have to check them, it's late!)
    WITH a AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_one),
    b AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_two),
    sourceqry AS
    (SELECT  b.col3 x
           , a.col1 y
           , a.col2 z
    FROM table_one a
        , table_two b
    WHERE a.col3 = 12345
    AND   a.col4 = 100
    AND   b.col5 = a.col5)
    SELECT apex_item.checkbox(1,x), y , z
    FROM sourceqry
    WITH a AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_one),
    b AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_two)
    SELECT  apex_item.checkbox(1,x), y , z
    FROM table_one a
        , table_two b
    WHERE a.col3 = 12345
    AND   a.col4 = 100
    AND   b.col5 = a.col5If the remote tables are at the same site, then you should have the same results. If they aren't you should get the same results but different to the original query.
    We aren't being told the real cardinality of the inners select here so the explain plan is distorted (this is normal for queries on remote and especially non-oracle sites). This hinders tuning normally but I don't think this is your problem at all. How many distinct values do you normally get of the column aliased 'x' and how many rows are normally returned in total? Also how are you testing response times, in APEX, SQL Developer, Toad SQLplus etc?
    Sorry for all the questions but it helps to answer the question, if I can.
    Cheers
    Ben
    http://www.munkyben.wordpress.com
    Don't forget to mark replies helpful or correct ;)

  • What is the best practice for running a long report/query against an active database?

    We are using SQL Server 2012 EE but currently do not have the option to run queries on a R/O mirror though that is my long term goal. I am concerned I may still run into the below issue in that scenario as well since the mirror would also be updating data I
    am querying.
    I have a view that joins across several tables from two databases and is used by an invoicing program on existing data. Three of these tables are also actively updated by ongoing transactions. Running a report that used this view did not use to be a problem
    but now our database is getting larger and we have run into some timeout problems for the live transactions coming in.
    First the report query was timing out so I set command timeout to 0 and reran the query which pegged all 4 CPUs 100% for 90 minutes and so I finally killed it. Strangely there were no problems with active transactions during that time so I'm wondering if the
    query was really running doing anything useful or somehow spinning and waiting. I reviewed the view and found a field I was joining on that was not indexed so created an index on that field, reran the report, which then finished in three minutes and all the
    CPUs were busy but not at all pegged out. Same data queried both times. I figured problem solved. Of course later, my boss ran a similar invoice report, with the same amount of data, and our live transactions started timing out 100% while his query was running.
    I did not get a chance to see the CPU usage during that time.
    I looked at the execution plan of the underlying view and added the suggested index but that did not help. When I run the just the view at SQL Server it does not seem to cause any problems and finished in a couple seconds. Perhaps something else going on in
    the reporting tool using the view.
    My main question is - Given I have to use the live and active database, what is the proper way to run a long R/O query/report so that active transactions can still continue to update
    tables that I am querying? sp_who2 did show transactions being blocked so I guess a long query accessing the tables blocks live transactions accessing those same tables, but certainly I'm not the only one doing this. I
    am considering adding "with (nolock)" but am hoping there is a better standard practice as that clause can return dirty data and I understand why. Thx, Dave
    Thanks, Dave
    Dave

    Hello
    You can change the DB isolation level to Read uncommitted
    http://technet.microsoft.com/en-us/library/ms378149(v=sql.110).aspx
    or use WITH (NOLOCK)
    I do use NOLOCK option for the dirty reads to avoid locks on the tables
    Javier Villegas |
    @javier_vill | http://sql-javier-villegas.blogspot.com/
    Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you

  • How to change report query dynamically in Oracle APEX?

    Hi,
    I want to dynamically change the where condition in APEX report query. Can anyone help me solve my this problem?
    (Just want to change the query which we change in Oracle Reports using lexical parameter to change &Where, &Order by etc. dynamically!!)
    Thanks, Praful

    Hi
    I've been using flexible queries in APEX for a few years now, and your question just added a whole new dimension to the flexible and powerful nature or writing reports in APEX.
    While APEX Interactive reporting has almost completely removed the need the equivalent of Lexicals in Oracle Reports, I thought it might be fun to try and use lexicals in an APEX report.
    Before we start I should summarise the powerful capability of APEX reporting to have oprtional parameters (lots and lots of them if this is needed).
    For each parameter, you simply add a page item which will hold the value of the parameter.
    The item/parameter can be populated by typing in the value, defining an LOV, using a date-picker etc.
    To make the parameter optional simply use an OR in the where clause.
    So for a apge item P200_PARAM1.....include
    WHERE (:P200_PARAM1 IS NULL
    OR COLUMN1 = :P200_PARAM1)
    This way you can either leave the page item null or type in / select a value from a LOV.
    There is a small quirk in APEX LOV's which sometimes returns a value of '%' or '%null%' - depending on the version - when no value is selected.
    See Patrick Wolf's solution for this at Re: Null value handling in LOVs
    I include this Application Process in all my APEX applications ;)
    Now let's look at using the equivalent of Oracle Reports Lexicals......
    First-off - this is based on the APEX SQL report - NOT Interactive Report.
    It relies on the fact that you can let the query be parsed only at runtime.
    1. Define an SQL report entering the 'core' of your query.
    With a query like SELECT ENAME, JOB FROM EMP
    Select 'Generic Columns' option in the 'Column Headings' section
    Finish the report creation
    2. Define a page item - say P200_LEXICAL - type text on the page
    3. Edit the report and update the SQL query to include your lexical page item
    SELECT ENAME, JOB FROM EMP &P200_LEXICAL. (REMEMBER THE '.' AT THE END)
    Ensure that the option "Use Generic Column Names (parse query at runtime only)" is selected at the bottom of the query
    4. Add a button to the page -using 'Create a button displayed among this region's items' the will submit the page.
    5. Run the page - you will see all the employee names and job desdriptions
    6. Enter a where clause into the 'Lexical' textbox - say "WHERE ENAME LIKE 'K%'" and click the 'Go' button
    Voila! your where clause is magically applied.
    Try any variant you like adding an ORDER BY clause etc...... this is FUN!
    7. Clear the value of the LEXICAL and click go.
    Edit the report and move the &P200_LEXICAL. into the selected columns (or add another one)
    SELECT ENAME, JOB &P200_LEXICAL. FROM EMP
    8. Run the page
    Enter ",SAL" in the textbox and "Go"
    We can add as many columns as we like (subject to the "Maximum number of generic report columns:" set below the SQL query in the report edit section)
    Now because we have all the flexibility in APEX of setting page items using SQL or PLSQL you can set the value of the lexical programatically, or just pre-set a few values in an LOV - the options are limitless.
    While I've never had the need to use lexicals - you can see that APEX provides the most Flexible Lexicals in town.
    Eat your heart out "Oracle Reports"!!!
    Have fun
    Mike

  • Report Query wizard error (in Shared Components)

    I have been following the <a target="_window" href="http://www.oracle.com/technology/products/database/application_express/howtos/howto_master_detail_pdf.html">How-To Create a Master-Detail PDF Report</a><br>
    <br>
    I'm using Apex 3.01 and Firefox 2.0.0.7<br>
    <br>
    When I have to create a Report Query in the shared components, I get through the wizard to the Create Report Query Layout page and for some reason, the Previous and Next buttons don't work. The only button that works is the Cancel button.<br>
    It seems to happen after I've downloaded the sample XML file from that page.<br>
    I've also noticed this happens when you go in to edit an existing Report Query and take a download of the XML...<br>
    On closer inspection it seems to be the buttons that have onclick="javascript:doSubmit..." behind them that don't work. Buttons with javascript:confirmDelete seem to still be active and work ok.<br>
    <br>
    But, the problem doesn't happen in IE7.<br>
    <br>
    I found this happened on both my local installation and on my apex.oracle.com instance.<br>
    <br>
    Has anyone else had this behavior or is this some dodgy local setting I have wrong?<br>
    <br>
    Gus..<br>

    Hi,
    This is posted in the wrong forum. This forum is for Oracle Berkeley DB. Please find the correct forum and post your question there.
    Regards,
    Alex Gorrod,
    Oracle Berkeley DB

  • Call to predefined Report Query for PDF download does nothing

    I am trying to download a PDF report which is based upon 2 queries. Each query has a where clause with values taken from page items. I have installed OBI Publisher 11.1.1.5 and used the OBI Publisher 11.1.1.5 Word plug-in to create the RTF file that I then uploaded to the Shared Components->Report Layout.
    I created a new region button to call the Report Query. However, whenever I click on the button to download the PDF, nothing happens. I have looked at the debug and the button appears to be executing OK, except that nothing happens.
    The APEX to OBIP configuration is working since I am able to have OBIP generate other report PDFs that aren't using the predefined query. Stated a bit differently, reports regions that have the Print Attributes set to "Enable Report Printing=Yes" and "Report Layout=Default Report Layout" work fine. Reports based upon the predefined query and launched using a region button do not do anything.
    Environment: APEX 4.1, DB 11.2.0.2, OBIP 11.1.1.5
    Any help with this PDF issue is greatly appreciated.
    Thanks,
    Reid

    Thank you again for your reply, Udo.
    Here are my responses:
    * As a matter of fact, I am doing a copy / paste from the predefined query to the report region source.
    ** What exactly do you mean by that? Don't you print the actual region?
    I need to produce a PDF that is the compilation of 4-5 queries. Therefore, I cannot print a region to PDF since APEX (as far as I know) does not allow for the printing of multiple regions (1 query per region) to a single PDF file. So, I am creating a PDF that is based upon multiple queries which I predefine in the shared components -> report queries. Then, I'm creating a region button that calls a downloadable report when it is clicked.
    Your question has made me realize that indeed it doesn't matter what query I have in the report region since I am calling a predefined report. When nothing was happening when I attempted to generate the PDF, I guess I started to think that the problem was with the queries on the page and so I made them match exactly with what the queries are in the shared components->report queries.
    Please advise if something is wrong with my understanding here.
    I checked the OBI Publisher logs (at least what I could locate) and I didn't see anything show up there.
    /u02/app/ohs/obip_mw/user_projects/domains/bifoundation_domain/servers/AdminServer/logs
    I checked the OHS access_log and I didn't see anything that looks like an error. I also don't see anything in the APEX page debug. It appears to process normally when the button is clicked.
    From the access_log:
    192.168.1.137 - APEX_PUBLIC_USER [27/Dec/2011:22:17:30 -0500] "GET /pls/apex/f?p=4000:RUN_PAGE:55206340610065:BRANCH_TO_PAGE_ACCEPT:NO::FB_FLOW_ID,FB_FLOW_PAGE_ID,F4000_P1_FLOW:103,235,103 HTTP/1.1" 302 -
    192.168.1.137 - APEX_PUBLIC_USER [27/Dec/2011:22:17:30 -0500] "GET /pls/apex/f?p=103:235:55206340610065::::: HTTP/1.1" 200 21588
    192.168.1.137 - APEX_PUBLIC_USER [27/Dec/2011:22:17:32 -0500] "POST /pls/apex/wwv_flow.accept HTTP/1.1" 302 -
    192.168.1.137 - APEX_PUBLIC_USER [27/Dec/2011:22:17:32 -0500] "GET /pls/apex/f?p=103:235:4495899155137965::::: HTTP/1.1" 200 21588
    Here is a look at the page debug:
    0.00246     0.00107     A C C E P T: Request="TRANSCRIPT_PDF"     4
    0.00350     0.00501     Metadata: Fetch application definition and shortcuts     4     
    0.00851     0.00080     alter session set nls_language="AMERICAN"     4     
    0.00931     0.00060     alter session set nls_territory="AMERICA"     4     
    0.00991     0.00078     NLS: CSV charset=WE8MSWIN1252     4     
    0.01069     0.00067     ...NLS: Set Decimal separator="."     4     
    0.01136     0.00083     ...NLS: Set NLS Group separator=","     4     
    0.01219     0.00082     ...NLS: Set g_nls_date_format="DD-MON-RR"     4     
    0.01301     0.00079     ...NLS: Set g_nls_timestamp_format="DD-MON-RR HH.MI.SSXFF AM"     4     
    0.01380     0.00077     ...NLS: Set g_nls_timestamp_tz_format="DD-MON-RR HH.MI.SSXFF AM TZR"     4     
    0.01457     0.00064     ...Setting session time_zone to -05:00     4     
    0.01522     0.00077     Setting NLS_DATE_FORMAT to application date format: DD-MON-YYYY HH:MIPM     4     
    0.01599     0.00094     Setting NLS_TIMESTAMP_FORMAT to application timestamp format: DD-MON-YYYY HH:MIPM     4     
    0.01693     0.00077     ...NLS: Set g_nls_date_format="DD-MON-YYYY HH:MIPM"     4     
    0.01770     0.00078     ...NLS: Set g_nls_timestamp_format="DD-MON-YYYY HH:MIPM"     4     
    0.01848     0.00068     ...NLS: Set g_nls_timestamp_tz_format="DD-MON-RR HH.MI.SSXFF AM TZR"     4     
    0.01916     0.00046     NLS: Language=en-us     4     
    0.01962     0.00219     ...metadata, fetch translated application info     4     
    0.02181     0.00088     ...fetch session state from database     4     
    0.02269     0.00096     fetch items     4     
    0.02365     0.00090     ...fetched 32 session state items     4     
    0.02455     0.00170     Authentication check: CUSTOM TABLE AUTH (NATIVE_CUSTOM)     4     
    0.02625     0.00074     ... sentry+verification success     4     
    0.02698     0.00057     ...Session ID 4495899155137965 can be used     4     
    0.02755     0.00056     ...Check session 4495899155137965 owner     4     
    0.02811     0.00064     Setting NLS_DATE_FORMAT to application date format: DD-MON-YYYY HH:MIPM     4     
    0.02875     0.00080     Setting NLS_TIMESTAMP_FORMAT to application timestamp format: DD-MON-YYYY HH:MIPM     4     
    0.02955     0.00062     ...NLS: Set g_nls_date_format="DD-MON-YYYY HH:MIPM"     4     
    0.03017     0.00069     ...NLS: Set g_nls_timestamp_format="DD-MON-YYYY HH:MIPM"     4     
    0.03086     0.00053     ...NLS: Set g_nls_timestamp_tz_format="DD-MON-RR HH.MI.SSXFF AM TZR"     4     
    0.03139     0.00130     ...Check for session expiration:     4     
    0.03269     0.00055     ...Metadata: Fetch Page, Computation, Process, and Branch     4     
    0.03323     0.00102     Session: Fetch session header information     4     
    0.03425     0.00047     ...Setting session time_zone to -5:00     4     
    0.03472     0.00187     ...metadata, fetch page info     4     
    0.03660     0.00092     ...Validate item page affinity.     4     
    0.03751     0.00050     ...Validate hidden_protected items.     4     
    0.03801     0.00061     ...Check authorization security schemes     4     
    0.03862     0.00095     Session State: Save form items and p_arg_values     4     
    0.03957     0.00081     ...Session State: Save "P235_TRANSCRIPT_ID" - saving same value: "7"     4     
    0.04038     0.00065     Processes - point: ON_SUBMIT_BEFORE_COMPUTATION     4     
    0.04102     0.00082     Branch point: Before Computation     4     
    0.04185     0.00054     Computation point: After Submit     4     
    0.04239     0.00079     Tabs: Perform Branching for Tab Requests     4     
    0.04317     0.00065     Branch point: Before Validation     4     
    0.04382     0.00111     Validations:     4     
    0.04493     0.00165     Perform basic and predefined validations:     4     
    0.04658     0.00070     Perform custom validations:     4     
    0.04728     0.00054     Branch point: Before Processing     4     
    0.04782     0.00057     Processes - point: AFTER_SUBMIT     4     
    0.04839     0.00054     Branch point: After Processing     4     
    0.04893     0.00096     ...Evaluating Branch: AFTER_PROCESSING type: "REDIRECT_URL" button: (No Button Pressed) branch: (Unconditional)     4     
    0.04989     0.00071     Stop APEX Engine detected     4     
    0.05059     0.00055     Stop APEX Engine detected     4     
    0.05114     0.00122     Final commit     4     
    0.05236     -     End Page Processing

  • Generic report query that will work against common table ..

    Context
    We have a custom audit log scheme that inserts all table changes into a backing table via triggers. For example, an insert into table ORDER would cause a insert into ORDER_AUD.
    Problem
    We want to build a generic report query that will work against any audit table.
    While constructing a report query for a class that uses inheritance, we see TopLink? add an extra where-clause.
    We are required to set the ReferenceClass? for the query, however, the tables we are querying are not mapped to TopLink?. We just want to map the query results to objects of the Reference Class.
    The extra where-clause specifies the table of the Reference Class, but since that table is not in the From clause, the query doesn't work.
    The ReportQuery? in Question
    public DatabaseQuery loadAuditHistory(Class cls, String audTableName ) {
    String emanAuditTableName = "eman_audit";
    ExpressionBuilder expressionBuilder = new ExpressionBuilder();
    Expression exp = expressionBuilder.getTable(audTableName)
    .getField("instance_id")
    .equal(expressionBuilder.getParameter("instanceId"))
    .and(expressionBuilder.getTable(audTableName).getField("audit_id")
    .equal(expressionBuilder.getTable(emanAuditTableName).getField("audit_id")));
    ReportQuery query = new ReportQuery(expressionBuilder);
    query.setReferenceClass(cls);
    query.setSelectionCriteria(exp);
    query.addArgument("instanceId");
    query.addAttribute("Changed By", expressionBuilder.getTable(emanAuditTableName).getField("audit_user"));
    query.addAttribute("Host", expressionBuilder.getTable(emanAuditTableName).getField("audit_host"));
    query.addAttribute("UTC Timestamp", expressionBuilder.getTable(emanAuditTableName).getField("audit_utc_timestamp"));
    query.addAttribute("Action", expressionBuilder.getTable(audTableName).getField("table_action_code"));
    Descriptor orderDescriptor = session.getDescriptor(cls);
    Vector mappings = orderDescriptor.getMappings();
    for (Iterator iter = mappings.iterator(); iter.hasNext();) {
    Object element = (Object) iter.next();
    if (element instanceof DirectToFieldMapping) {
    DirectToFieldMapping mapping = (DirectToFieldMapping)element;
    DatabaseField field = mapping.getField();
    String tableName = field.getTableName();
    String fieldName = field.getName();
    query.addAttribute(fieldName, expressionBuilder.getTable(audTableName).getField(fieldName));
    Expression version = expressionBuilder.getTable(audTableName).getField("version_id");
    query.addOrdering(version.descending());
    query.setName(GET_AUDIT_HISTORY);
    return query;
    Code Generated by the ReportQuery?
    SELECT t0.audit_user, t0.audit_host, t0.audit_utc_timestamp,
    t1.table_action_code, t1.INSTANCE_ID, t1.STATUS,
    t1.REQUESTER, t1.DESCRIPTION, t1.RECIPIENT
    FROM eman_audit t0, example_order_aud t1
    WHERE (((t1.instance_id = 60432)
    AND (t1.audit_id = t0.audit_id))
    AND (EXAMPLE_ORDER.CLASS_NAME = 'eman.infra.toplink.example.project.model.Order'))
    ORDER BY t1.version_id DESC
    Descriptor used to Map Oder.class
    public Descriptor buildOrderItemDescriptor() {
    Descriptor descriptor = new Descriptor();
    descriptor.setJavaClass(eman.infra.toplink.example.project.model.OrderItem.class);
    descriptor.addTableName("ORDERITEM");
    descriptor.addPrimaryKeyFieldName("ORDERITEM.INSTANCE_ID");
    // Inheritance properties.
    descriptor.getInheritancePolicy().setClassIndicatorFieldName("ORDERITEM.CLASS_NAME");
    descriptor.getInheritancePolicy().useClassNameAsIndicator();
    // Descriptor properties.
    descriptor.useSoftCacheWeakIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteSoftCacheWeakIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("ORDERITEM.INSTANCE_ID");
    descriptor.setSequenceNumberName("CIM_ID");
    VersionLockingPolicy lockingPolicy = new VersionLockingPolicy();
    lockingPolicy.setWriteLockFieldName("ORDERITEM.VERSION_ID");
    descriptor.setOptimisticLockingPolicy(lockingPolicy);
    descriptor.setAlias("OrderItem");
    // Query manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    //Named Queries
    // Event manager.
    // Mappings.
    DirectToFieldMapping instanceIdMapping = new DirectToFieldMapping();
    instanceIdMapping.setAttributeName("instanceId");
    instanceIdMapping.setFieldName("ORDERITEM.INSTANCE_ID");
    descriptor.addMapping(instanceIdMapping);
    DirectToFieldMapping ItemNumberMapping = new DirectToFieldMapping();
    ItemNumberMapping.setAttributeName("ItemNumber");
    ItemNumberMapping.setFieldName("ORDERITEM.ITEM_NUMBER");
    descriptor.addMapping(ItemNumberMapping);
    DirectToFieldMapping QuantityMapping = new DirectToFieldMapping();
    QuantityMapping.setAttributeName("Quantity");
    QuantityMapping.setFieldName("ORDERITEM.QUANTITY");
    descriptor.addMapping(QuantityMapping);
    OneToOneMapping orderMapping = new OneToOneMapping();
    orderMapping.setAttributeName("order");
    orderMapping.setReferenceClass(eman.infra.toplink.example.project.model.Order.class);
    orderMapping.setRelationshipPartnerAttributeName("orderItems");
    orderMapping.dontUseIndirection();
    orderMapping.addForeignKeyFieldName("ORDERITEM.ORDER_ID", "EXAMPLE_ORDER.INSTANCE_ID");
    descriptor.addMapping(orderMapping);
    return descriptor;

    I'm am very confused as to what you are trying to do, are you trying to query Order objects from the ORDER_AUD historical table instead of the table that the class is mapped to?
    TopLink 10.1.3 (DP3) has built in support for historization, you may wish to investigate this support to allow historical querying of your audit tables.
    In general you cannot use a ReportQuery to do this, a ReportQuery is for querying data from objects based on an object-level criteria. I think that you want to query objects, but just using different SQL than the descriptors are mapped to.
    You could do this through a custom SQL read query,
    i.e.
    ReadAllQuery query = new ReadAllQuery(Order.class);
    query.setSQLString("Select * from ORDER_AUD where INSTANCE_ID = #id");
    query.addArgument("id");
    Vector argumentValues = new Vector(1);
    argumentValues.add(id);
    List objects = (List) session.executeQuery(query, argumentValues);
    As long as the field names in the audit and the original table matched this would work. However if this is a historical table, then I would guess that there might be multiple objects with the same id, so querying these historical objects could confuse the TopLink cache. You could set dontMaintainCache() on the query to avoid this.
    In general you would probably be much better off having two sessions, one with the descriptors mapped to the normal tables, and one with the descriptors mapped to the audit tables. Then you would be able to query both using regular object-level queries.

Maybe you are looking for