Dynamic query to produce crosstab/pivot report

Hello,
I've not been able to find any examples similar to my situation but perhaps I'm using the wrong search phrases...
I'm basically trying to create a cross-tab type report based on a dynamic query (since I do not know how many accounts a person has):
select '  SELECT x.name, x.type, ' from dual
union
select ' max(decode(x.account,'''||m.account||''',x.amount,null)) as "'||substr(s.proj||' '||m.account,1,30)||'",'
  from db1.manager m, db1.person p, pi.charges c, db1.status s
where m.manager_id = p.id
   and M.ACCOUNT_ID = C.ACCT_ID
   and M.ACCOUNT_STRING = S.project
   and C.JNL = (select max(id) from db1.journ j where j.TYPE ='M')
   and p.username = :username
   and nvl(M.END_DATE, sysdate +1) >= sysdate
group by m.account, s.proj
union
select 'sum(x.amount) grand_total from (select m.account, c.name, c.type, c.amount '
          ||'from db1.manager m, db1.person p, pi.charges c '
          ||'where m.manager_id = p.id '
          ||'and p.username = :P68_PRINC '
          ||'and c.acct_id = m.account_id '
          ||'and c.jnl = (select max(id) '
          ||'from db1.journ j where j.TYPE =''M'')) x '
          ||' group by type, name' from dualThe output from this query for the particular manager I selected is:
SELECT x.name, x.type,
max(decode(x.account,'12012',x.amount,null)) as "Internal 12012",
max(decode(x.account,'17929',x.amount,null)) as "Staged 17929",
max(decode(x.account,'18054',x.amount,null)) as "Help Software 18054",
max(decode(x.account,'3428',x.amount,null)) as "Mow 3428",
max(decode(x.account,'3428',x.amount,null)) as "Mow 3428_1",
max(decode(x.account,'3508',x.amount,null)) as "Stampede 3508",
max(decode(x.account,'9102',x.amount,null)) as "Open Collaborative 9102",
sum(x.amount) grand_total
from (select m.account, c.name, c.type, c.amount
from db1.manager m, db1.person p, pi.charges c
where m.manager_id = p.id
    and p.username = :P68_PRINC
    and c.acct_id = m.account_id
    and c.jnl = (select max(id)
   from db1.journ j where j.TYPE ='M')) x
  group by type, nameThis query generates another query that ultimately produces the report below (please pardon the alignment) that I want to see on a report page.
NAME     TYPE     Internal 12012     Staged 17929     Help Software 18054     Mow 3428     Mow 3428_1     Stampede 3508     Open Collaborative 9102     GRAND_TOTAL
#EXAM1221     M                                                                            22                                                                                             22
#EXAM1222     M                          14.83             14.77                     12.56                          2.22                                                          44.38
#EXAM1223     M                          6.73                 6.7                             5.7                                  1                                                          20.13
THOEORY       M                          106.5                                                                                                                                      106.5Should I be using the report type that is based on a 'PL/SQL function body returning SQL query' for this type of report??? If so, how does that get set up?
Thanks in advance!
~Jake

This solution works in that it generates the proper query. I can copy the query (from debug mode) and paste it in TOAD and it works perfectly. However, in the report page it tells me: "report error:ORA-01403: no data found".
I found this thread: report error: ORA-01403: no data found when SUM columns
I did have a couple other regions on the page (previous attempts) that were hidden so I deleted them completely. Still no luck.
I am also summing up several columns...if that has anything to do with it.
Does anyone have any suggestions?
Thanks again!!!
~Jake
Edited by: jhammer on Jul 27, 2010 11:02 AM

Similar Messages

  • Really working Crosstab / Pivot Report example

    try it here:
    http://apex.oracle.com/pls/otn/f?p=20819:2
    Details:
    Create Report - based on PL/SQL ************************************
    DECLARE
    l_return_value VARCHAR2(32000) DEFAULT NULL;
    BEGIN
    l_return_value := PK_PIVOT.PivotSQL('SELECT * FROM TESTDATA', 'country,city,product','FDate', 'SUM', 'amount', nvl(:P2_PAGENUMBER,1) );
    --:P2_PAGENUMBER - Textbox above the report
    RETURN l_return_value;
    END;
    Create Supporting PACKAGE PK_PIVOT ************************************
    create or replace
    PACKAGE PK_PIVOT
    --AUTHID CURRENT_USER
    as
    --code based on famous Tom Kyte's books examples
    --but not copy-pasted from there
    type refcursor is ref cursor;
    type array is table of varchar2(30);
    type array_varchar2 is table of varchar2(255);
    Function PivotSQL (
    p_query in varchar2, --query string which returns data you want to make crosstab on
    p_rowfields in varchar2, --row fields separated by comma
    p_columnfield in varchar2, --one column field
    p_function in varchar2,--aggregate function ('SUM','AVG','COUNT','MIN','MAX')
    p_functionfield in varchar2 --field for aggregate function
    , p_page in number default 1--page from right to left (not all columns can be shown on one page)
    ) return varchar2; --returns query text for crosstab
    example:
    SELECT PK_CROSSTAB.PivotSQL('SELECT * FROM scott.emp','empno','job','sum','sal') FROM SYS.DUAL
    SELECT deptno
    ,sum(DECODE(job,'BOSS',sal,null)) as BOSS
    ,sum(DECODE(job,'FIN',sal,null)) as FIN
    ,sum(DECODE(job,'HR',sal,null)) as HR
    ,sum(DECODE(job,'Sales',sal,null)) as Sales
    FROM (SELECT * FROM scott.emp)
    GROUP BY deptno
    ORDER BY deptno
    end;
    create or replace PACKAGE BODY PK_PIVOT as
    Procedure FormatParam (var_data in varchar2, var_type in number, out_decode in out varchar2, out_col in out varchar2);
    Function PivotSQL (
    p_query in varchar2,--
    p_rowfields in varchar2,
    p_columnfield in varchar2,
    p_function in varchar2,
    p_functionfield in varchar2,
    p_page in number default 1
    ) return varchar2
    as
    l_max_cols number;
    l_query long;
    l_columnnames array_varchar2 :=array_varchar2();
    l_cursor refcursor;
    tmp long;
    --dbms_sql types:
    l_theCursor integer default dbms_sql.open_cursor;--get col types
    l_colCnt number default 0;
    l_descTbl dbms_sql.desc_tab;
    col_num number;
    l_columnfieldtype number;
    --decode names   
    o_decode varchar2(50);
    o_col varchar2(50);
    l_cols_per_page number := 50;
    l_begcol number;
    l_endcol number;
    begin
    --check params
    IF instr(p_columnfield,',')>0 THEN
    raise_application_error (-20001, 'Can use only 1 columnfield');
    ELSIF upper(p_function) not in ('SUM','AVG','COUNT','MIN','MAX') THEN
    raise_application_error (-20001, 'Can use only standard aggregate functions');
    END IF;
    /* analyse query */
    dbms_sql.parse(l_theCursor, p_query, dbms_sql.native);
    /* get described columns for analysed query */
    dbms_sql.describe_columns(l_theCursor, l_colCnt, l_descTbl);
    /* Tom Kyte:
    * Following loop could simply be for j in 1..col_cnt loop.
    * Here we are simply illustrating some of the PL/SQL table
    * features.
    col_num := l_descTbl.first;
    loop
    exit when (col_num is null);
    --find column field type
    if l_descTbl(col_num).col_name=upper(p_columnfield) then
    l_columnfieldtype:=l_descTbl(col_num).col_type;
    --dbms_output.put_line('Col#:'||col_num||' Name:'||l_descTbl(col_num).col_name||' Type:'||l_descTbl(col_num).col_type);
    end if;
    col_num := l_descTbl.next(col_num);
    end loop;
    --return 'test ok';
    -- figure out the column names we must support for horizontal cross
    if (p_columnfield is not null) then
    tmp:='SELECT DISTINCT ' || p_columnfield || ' FROM (' || p_query || ') ORDER BY ' || p_columnfield;
    -- dbms_output.put_line('columns cursor:'||tmp);
    OPEN l_cursor for tmp;
    LOOP
    l_columnnames.EXTEND;
    FETCH l_cursor into l_columnnames(l_columnnames.COUNT);
    --dbms_output.put_line('l_columnnames:'||l_columnnames(l_columnnames.COUNT));
    EXIT WHEN l_cursor%NOTFOUND;
    END LOOP;
    CLOSE l_cursor;
    -- execute immediate 'SELECT DISTINCT ' || p_columnfield || ' FROM (' || p_query || ')' bulk collect into l_columnnames ;
    else
    raise_application_error (-20001, 'Cannot figure out max cols');
    end if;
    -- Now, construct the query that can answer the question for us...
    l_query := 'SELECT ' || p_rowfields ;
    l_begcol:=l_cols_per_page*(p_page-1)+1;
    l_endcol:=l_cols_per_page*p_page;
    if l_begcol>l_columnnames.count-1 then
    l_begcol := l_columnnames.count-1;
    end if;
    if l_endcol>l_columnnames.count-1 then
    l_endcol := l_columnnames.count-1;
    end if;
    --for i in  1 .. l_columnnames.count-1 loop
    for i in l_begcol..l_endcol loop
    FormatParam(l_columnnames(i),l_columnfieldtype, o_decode, o_col);--format params
    l_query := l_query || ',' || p_function || '(DECODE(' || p_columnfield || ',' || o_decode || ','|| p_functionfield ||',null)) as "'|| o_col ||'" ' ; --" для строк с пробелами
    end loop;
    l_query := l_query || ' FROM (' || p_query || ')';
    l_query := l_query || ' GROUP BY ' || p_rowfields || ' ORDER BY ' || p_rowfields;
    /* close cursor */
    dbms_sql.close_cursor(l_theCursor);
    return l_query;
    EXCEPTION
    WHEN OTHERS THEN
    /* close cursor */
    dbms_sql.close_cursor(l_theCursor);
    raise_application_error (-20001,'Error in PivotSQL:' || SQLERRM);
    end;
    --=========================
    Procedure FormatParam (var_data in varchar2, var_type in number, out_decode in out varchar2, out_col in out varchar2)
    --format parameter based on its type - for PivotSQL
    --get parameter and its type
    -- return strings for decode function and column name
    /* dbms_sql.describe_columns types:
    DATE Type:12
    Varchar2 Type:1
    Number Type:2
    IS
    BEGIN
    IF var_data is null THEN
    out_decode:='NULL';
    out_col:='==NULL==';
    ELSIF var_type = 1 THEN -- Varchar2
    out_decode:=''''||var_data||'''';--add quotes
    out_col:=substr(var_data,1,30);
    ELSIF var_type = 2 THEN --Number
    out_decode:=var_data;--do nothing
    out_col:=substr(var_data,1,30);
    ELSIF var_type = 12 THEN --DATE
    out_decode:='to_date('''||var_data||''')';--format as internal date
    out_col:=to_char(to_date(var_data),'YYYY-MM-DD');
    ELSE
    out_decode:='== UNDEFINED TYPE:'||var_type;
    out_col:='== UNDEFINED TYPE';
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error (-20001,'Error in FormatParam:' || SQLERRM);
    END;
    end;

    Hi,
    Thank you for providing such an excellent piece of code. I have used it and it works like a charm. However I faced a problem today and needed your help.
    I am executing this code using the following code :
    SELECT PK_PIVOT.PivotSQL('SELECT sfid.bill_date ,cust.customer_name FROM split_file_detail sfd,customer cust,split_file_invoice_details sfid where sfd.CUSTOMER_SYS_ID=cust.CUSTOMER_SYS_ID and sfid.SPLIT_FILE_DETAIL_SYS_ID = sfd.SPLIT_FILE_DETAIL_SYS_ID'
    ,'cust.customer_name','bill_date','count','cust.customer_name') FROM SYS.DUAL
    Now when I do so I get the following error :
    ORA -20001 : Error in PivotSQL: ORA-06502 and ORA-06512.
    Now I guess the error maybe because:
    1. The p_query parameter is huge and the tmp long type is not able to hold the value.
    2. bill_date holds 200+ values and the ref_cursor is not able to handle it.
    I have tried breaking p_query down to some more bits but I face the problem when I concatenate them back together.
    Can you help me please?

  • Creating a Crosstab/Pivot report in Oracle Apex

    Hello,
    I want to create a matrix view of a report in the following format. tried a lot of ways llike data pivoting, etc. but most of the ways use aggregate functions.
    format in which i require data is:
    ID NAME LEVEL PROJECT LOCATION ORACLE FORMS ORACLE REPORTS JAVA C++
    AAA123 ABC 2 AB AC Expert Aware Expert
    AAA124 DEF 3 BC AD Expert Proficient Aware
    The data in the table/view is in the format:
    ID NAME LEVEL PROJECT LOCATION Description Proficiency_ID
    AAA123 ABC 2 AB AC ORACLE FORMS Expert
    AAA123 ABC 2 AB AC ORACLE REPORTS Aware
    AAA123 ABC 2 AB AC JAVA Expert
    and similarly for other ID's.
    Since i need character values, aggregate functions would not be of much use.
    Thanks
    Varun
    Can anyone help me with this????

    Hi Arnaud,
    Saw the documentation that you had added and thanks for that..........but it is using sum(decode(...................
    which is an aggregate function but when i want to print character values for a certain distinct column value, that is where i am facing a problem..
    Hope you understood what i am saying:
    the id, name, level, prject, location will remain uniques and then i want proficiency to be put against each technology in a single row with al the technologies being disitnct columns..
    Thanks
    Varun

  • Generating Dynamic Query for Ad-Hoc Reports

    Hello,
    What is the best way to create a dynamic query to generate ad-hoc reports? I have a couple of ideas but not sure which would work best and be most flexible.
    I would like our users to be able to check checkboxes for what data they would like returned in their report. The data would be pulled from a number of tables, 10+, depending on what pieces of data they checked.
    Should I write one dynamic query, with a bunch of IF statements in it?
    Should I write many individual queries and then join them together in a temp query?
    Should I create a temp table on our SQL server which contains the data from all of the tables; then query that? (I am worried about data being out-of-date with this option.)
    Which one of these solutions should I go with or is there a better solution that I am not considering?
    Thanks for the help.
    Josh

    Do you mean a Stored Procedure? Would the Stored Procedure then have one query on it with a bunch if IF statements? Maybe a bad example, but something like this?
    Yep.
    I haven't written a proc for a coupla years (I have DB people to do that for me now, bless 'em), but every DB is different, so the approach will vary depending on what DB you have.  It's perhaps time to buy a book or do a google or something.
    Adam

  • Dynamic query table for report based on LOV selected

    Hi,
    Need some suggestion and guidance how to dynamically query table via lov for report .
    Scenario:
    Table, TABLE_LIST, has tablename (table in DB) and filter (for where clause) column. The TABLENAME_LOVE is derived from table TABLE_LIST.
    SELECT TABLENAME D, TABLENAME R FROM TABLE_LIST
    In Page 2,a page select list item,P2_TABLENAME to use TABLENAME_LOV
    All data in tables in the table_list have identical structure (columns, triggers, primary key, and so on).
    I want to have the report region query from the table based on selected LOV.
    Example,
    Tablename Filter
    TB1
    CD2 ACTIVE='Y'
    When select TB1, the report regin will query based on TB1.
    When select CD2, the report regin will query based on CD2 WHERE ACTIVE='Y'
    Question:
    How can I query based on &P2_TABLENAME. WHERE &P2_FILTER.
    Like
    select col1, col2 from &P2_TABLENAME WHERE &P2FILTER
    Greatly appreciate any suggestion and some guidance.
    Tigerwapa

    Hi,
    You should always post your Apex version, DB version and other information as suggested in the FAQ.
    And the moment you talk report you should state whether it is IR or Classic.
    As for your query, have you explored the Report type "SQL Query (PL/SQL function body returning SQL query)" ?
    That might be a good fit for what you are trying to achieve.
    Regards,

  • Dynamic Query in Report Builder

    HI
    I have a doubt:
    I need to receive a parameter in my report and I need this parameter in the query, that means, I need to create a dynamic query depending on the value that I receive in one of the parameters that has my report.
    I tried to use the resource of Searching by Reference Cursor tool, it is a blue circle in the Data Model View of Report Builder.
    When I click this tool, I have an initial code, It is:
    function QR_1RefCurDS return <RefCurType> is
    begin
    end;
    In PL/SQL I tried to create to test and to play, this code:
    Note: If you want to try only to test, it is simple and works:
    create or replace package TEST_REFCURTYPE as
    type refcurtype is ref cursor;
    function TEST_REFCURTYPE (P_DATE_TO nvarchar2) return refcurtype;
    end;
    create or replace package body TEST_REFCURTYPE as
    function TEST_REFCURTYPE (P_DATE_TO nvarchar2)
    return refcurtype is
    refcur refcurtype;
    mysql varchar(1000);
    begin
    If P_DATE_TO is not null then
    mysql := 'select '''|| P_DATE_TO ||''' from dual';
    else
    mysql := 'select sysdate from dual';
    end if;
    open refcur for mysql;
    return refcur;
    end;
    end;
    The problem is to pass this example of code to the function QR_1RefCurDS, I do not have a place to make reference to the type:
    type refcurtype is ref cursor;
    I tested the Unit Program in the Report Builder but it did not work, because all the code I try to write and create, for example in the Event BEFORE REPORT, it opens  Funcion( ) …., and I can not make reference to the type refcurtype inside a Function( ).
    Would you help me please?
    Or there is another way to make a dynamic query in the Report Builder?
    Sorry for my English, I am a Brazilian living in Spain.

    Hi,
    you can use lexical parameters in your queries. Instead of a ":" use in the query before the parameter a "&". Then the parameter stands for a part of the query and not for a value (Bind parameter). In the before report trigger you can set this parameters. They can contain parts of SQL like order or where. Make sure that the default value for this lexical parameters are set to get a valid query.
    SELECT ENAME, &p_column as COL2 FROM EMP &p_order
    and in the trigger something like
    IF :p_which_column = 1 THEN
    :p_column := 'SAL'
    ELSE
    Saludos
    Rainer

  • Dynamic Query for a report

    Hi,
    I have to generate a report which contains a query with database link. This database link is not hard coded and would be picked up from another report which contans a link to this report. So this database link value for the query could be any. Can anyone guide me hot to write a dynamic select statement so that i could append database link value at run time.
    Thanks
    Salman

    Hi,
    You can not directly use a PL/SQL query to create an Interactive Report - that is not yet available.
    What you could do is create a collection from your query and then use that for the report. Have a look at: [http://download-uk.oracle.com/docs/cd/B32472_01/doc/appdev.300/b32471/advnc.htm#BABGHJFD].
    In there, you will see APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY - this allows you to create a collection from a string. You could add a PL/SQL process to your page that runs "On Load: Before Header" that actually creates the collection. Something like:
    BEGIN
    IF APEX_COLLECTION.COLLECTION_EXISTS('MYCOLLECTIONNAME') THEN
      APEX_COLLECTION.DELETE_COLLECTION('MYCOLLECTIONNAME');
    END IF;
    APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('MYCOLLECTIONNAME','MY SQL QUERY STRING');
    END;Your Interactive Report can then be based on:
    SELECT SEQ_ID, C001, C002, C003, ...
    FROM APEX_COLLECTIONS
    WHERE COLLECTION_NAME = 'MYCOLLECTIONNAME'The tricky part is the headings as these would tend to be the SEQ_ID, C001, C002, C003, etc column names from the collection itself.
    To get around this, make sure that the report's sql statement includes as many Cnnn columns as you will need for the widest of the reports. Before doing anything else, run the report once to make sure that all these columns are included in the output.
    Then, through Shared Components, Application Items, create items that will hold heading names - for example, G_HEADING1, G_HEADING2 etc - one for each possibile column.
    Now, update the process to:
    BEGIN
    IF APEX_COLLECTION.COLLECTION_EXISTS('MYCOLLECTIONNAME') THEN
      APEX_COLLECTION.DELETE_COLLECTION('MYCOLLECTIONNAME');
    END IF;
    IF ..test1.. THEN
      APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('MYCOLLECTIONNAME','MY SQL QUERY STRING 1');
      :G_HEADING1 := 'ColumnHeading1Value';
      :G_HEADING2 := 'ColumnHeading2Value';
      :G_HEADING3 := NULL; -- column not used for this query, so set it to null
    ELSIF ..test2 .. THEN
      APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('MYCOLLECTIONNAME','MY SQL QUERY STRING 2');
      :G_HEADING1 := 'ColumnHeading1Value';
      :G_HEADING2 := 'ColumnHeading2Value';
      :G_HEADING3 := 'ColumnHeading3Value';
    ELSIF ...etc...
      .. etc ...
    END IF;
    END;Finally, on the report itself, set the column headings to *&G_HEADING1.*, *&G_HEADING2.* etc. Then, on each column, set a Condition of "Value of Item in Expression 1 is NOT NULL" and in Expression 1, enter in the application item for that column - eg, G_HEADING1
    I have done all that here: [http://apex.oracle.com/pls/otn/f?p=16338:5] - select either Departments or Employees from the list and the report will change.
    Andy

  • Interactive report based on dynamic query

    Hello
    I am using Apex 4.1 and have a requirement to create an interactive report based on a dynamic query. This option is available in Classic report but in Interactive this feature is not there. Tried using collections or just a view (thought of changing the view definition during "On load", but structure of the report is already defined based on the definition of the view at design time).
    Is there any way of achieving this?
    Appreciate any help!
    Thanks
    aks

    Try looking at this: http://rakeshjsr.blogspot.com/2010/10/oracle-apex-interactive-report-based-on.html
    Thank you,
    Tony Miller
    Dallas, TX

  • Parameter in form for dynamic query in report

    Hello,
    I want to send parameters to report for replacing a dynamic query. I don't know how to make it...
    1.I want my select statement like
    select * from emp
    &p_where_clause
    2.I want to transfer parameters to report to replace the &p_where_clause.
    3.I know I should create a parameter list first, and then use add_parameter built-in to add the parameter, but what I don't know is the correct format of the add_parameter statement.
    4.I know the common format is add_parameter(paramlist,'TEXT_PARAMETER',value) , is it the same format if I want to transfer a select statement to report such as "where deptno in ('25','28','30')" for replacing &p_where_clause in report?
    Thanks in advance
    Joseph

    I appreciate your reply, but I am still a little confused...
    Actually, I want to pass the where clause to report by different condition. Such as when the user choose the deptment 1, then I can transfer the "where dept_no = '1' and empno > 500", or user choose the deptment 2, I can transfer "where dept_no = '2' and company = '0001'". What I want is to pass different where clause to report according to different condition.
    So is it right the statement should be like
    DECLARE
    vWhere1 varchar2 := 'where dept_no = "1" and empno > 500';
    vWhere2 varchar2 := 'where dept_no = "2" and company = "0001"';
    BEGIN
    IF choose = 1 THEN
    ADD_PARAMETER(&P_WHERE_CLAUSE, TEXT_PARAMETER, vWhere1);
    ELSIF choose = 2 THEN
    ADD_PARAMETER(&P_WHERE_CLAUSE, TEXT_PARAMETER, vWhere2);
    END IF;
    END;
    THANKS AGAIN!!
    Joseph

  • Dynamic query in updatable report

    I have generated a updatable report with the folowing select:
    select
    "INSTALLATIEID",
    "INSTALLATIEID" INSTALLATIEID_DISPLAY,
    "CO_DRUK" druk,
    "CO_H2O" h2o,
    "CO_O2" o2,
    "CO_O2_11" o2_11,
    "CO_TEMP" temp
    from "#OWNER#"."CORRECTIE"
    The table correctie has above the 50 columns (the same columns for different components) so I want to change the query in:
    select
    "INSTALLATIEID",
    "INSTALLATIEID" INSTALLATIEID_DISPLAY,
    "&P50_COMP._DRUK" druk,
    "&P50_COMP._H2O" h2o,
    "&P50_COMP._O2" o2,
    "&P50_COMP._O2_11" o2_11,
    "&P50_COMP._TEMP" temp
    from "#OWNER#"."CORRECTIE"
    The item P50_COMP will be filled with a default value and is a select list with submit.
    The problem is when I change the query in the above way, the query cannot be parsed and I cannot applay the changes without parsing the query.
    Also not when I use Generic Column Names (parse query at runtime only)
    Can somebody help me with this problem.

    Fred,
    You should switch to a PL/SQL Function Body Returning SQL Statement (Dynamic Query) in order to achieve this. Your Function would look like this:
    declare
      l_sql varchar2(32767);
    begin
      l_sql := 'select
    "INSTALLATIEID",
    "INSTALLATIEID" INSTALLATIEID_DISPLAY,
    "' || :P50_COMP || '._DRUK" druk,
    "' || :P50_COMP || '._H2O" h2o,
    "' || :P50_COMP || '._O2" o2,
    "' || :P50_COMP || '._O2_11" o2_11,
    "' || :P50_COMP || '._TEMP" temp
    from "#OWNER#"."CORRECTIE"';
    return l_sql;
    end;Thanks,
    - Scott -

  • Report Query using a Named Column Report Layout fails to produce PDF

    I am testing FOP and the Shared Component Report Queries query with a Named Column Report Layout. The xsl file was built using Stylus Studio and worked fine with the saved XML data file in Stylus Studio.
    500 Internal Server Error
    500 Internal Server Error
    Servlet error: An exception occurred.
    The current application deployment descriptors do not allow for including it in this response.
    Please consult the application log for details.
    I assume this is a message from FOP. What do I do now?
    tia,
    Sam

    Sam,
    I would suggest to take APEX out of the picture first and see if you can get this to work directly with your FOP solution, i.e. generate the XML data and take your XSL file and then post it directly to the FOP JSP (or whichever rendering engine you use). If this works, the problem might be somewhere in your APEX configuration. If it doesn't work, then the problem is likely in your XSL or XML structure. Here's how you can setup a static HTML page to post your XML and XSL to FOP:
    http://marcsewtz.blogspot.com/2008/06/heres-another-posting-on-pdf-printing.html
    Regards,
    Marc

  • Dynamic query report problem

    I have followed the tutorial in on dynamic query and created a region where the type is SQL Query (PL/SQL function body returning SQL Query)
    The source is
    declare
    q varchar2(4000);
    teatid NUMBER := :P305_TARGET_ID;
    begin
    wwv_flow.debug('teatid = ' || teatid);
    q:=' select f.id, ';
    q:=q||' f.eat_id ';
    q:=q||' from xmlTransactions f ';
    q:=q||' where f.eat_id = ' || teatid; -- I've also tried putting :P305_TARGET_ID here
    wwv_flow.debug('sql = ' || q);
    return q;
    end;
    I have chosen "Use Generic Column Names...".
    When I run the page, I get NO ROWS FOUND. However, when I cut and paste the SQL statement printed out by the debug statement and run it, it returns rows. Both debug statements print correct values.
    I'm not sure what the problem is here, but basically, I want to do a query where I substitute a value passed into the page from another page.
    In this case the value in P305_TARGET_ID is passed in via a button spawning a popup as in var url = 'f?p=&APP_ID.:305:&APP_SESSION.::::P305_TARGET_ID:' + targetID;
    APEX version is 3.0.1.00.08
    Thank you.
    - JohnW

    Hi, JohnW
    I don't understand why you use a dynamic query for that.
    A "direct" SQL query like this :
    select f.id,f.eat_id from xmlTransactions f where f.eat_id=:P305_TARGET_ID;
    should work.
    Mike

  • Query a stored procedure that exec's a dynamic query. Error Linked server indicates object has no columns

    I have a stored procedure that dynamically creates a pivot query.  The procedure works and returns the correct data.  Now I have a requirement to show this data in reporting system that can only pull from a table or view.  Since you can not
    create a dynamic query in a view I tried to do a select from using openquery. 
    Example 'Select * from OpenQuery([MyServername], 'Exec Instance.Schema.StoredProcedure')
    I get the error back "the linked server indicates the object has no columns".  I assume this is because of the first select statement that is stuffing the variable with column names. 
    CODE FROM PROCEDURE
    Alter PROCEDURE [dbo].[Procedure1]
    AS
    BEGIN
    SET NOCOUNT ON
    Declare @cols nvarchar(2000),
      @Tcols nvarchar(2000),
      @Sql nvarchar (max)
    select @cols = stuff ((
          Select distinct '], ['+ModelName + '  ' + CombustorName
           from CombustorFuel cf
           join Model m on cf.modelid = m.modelid
           join Combustors cb on cf.CombustorID = cb.CombustorID
           where cf.CombustorID > 0
           for XML Path('')
          ),1,2,'')+']'
    Set @Tcols = replace(@Cols, ']', '] int')
    --Print @Tcols   
    --Print @Cols
    Set @Sql = 'Select GasLiquid, FuelType, '+ @Cols +'
    from
     Select GasLiquid, FuelType, ModelName+ ''  '' +CombustorName ModelCombustor, CombFuelStatus+''- ''+CombFuelNote CombFuelStatusNote
      from Frames f
      join Family fa on f.Frameid = fa.frameid
      join Model m on fa.FamilyID = m.FamilyID
      join CombustorFuel cf on m.Modelid = cf.modelid
      Join Combustors c on cf.CombustorId = c.CombustorID
      join FuelTypes ft on cf.FuelTypeID = ft.FuelTypeID
      where cf.CombustorFuelID > 0
        and CombustorName <> ''''
     ) up
    Pivot
     (max(CombFuelStatusNote) for ModelCombustor in ('+ @Cols +')) as pvt
    order by FuelType'
    exec (@Sql)

    Then again, a good reporting tool should be able to do dynamic pivot on its own, because dynamic pivoting is a presentation feature.
    SSRS Supports dynamic columns: Displaying Dynamic Columns in SSRS Report
    SQL Reporting Services with Dynamic Column Reports
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
    Displaying and reading are two very different things.
    #1) SSRS Needs a fixed field list on the input side to know what what to make available in the designer.
    #2) SSRS cant read "exec (@Sql)" out of a proc, even if there is a fixed number of columns (at
    least it can't use it to auto build the field list from the proc)
    I use dynamic SQL in my report procs on a fairly regular basis and I've found it easiest to simply dump
    the results of my dynamic sql into a temp table at the end of the procs and then select from the temp table.
    Basically, Erland is correct. Stop trying to pivot in the query and let SSRS (or whatever reporting software you're using) handle it with a Martix.
    Jason Long

  • Crosstab/Pivot queries.  How can I edit using Apex?

    Hello, all.
    I currently have a report within Apex that displays the results of a crosstab/pivot query as shown below. This works fine.
    What I now need to do is provide edit functionality on each row. The row does not have an individual ID column per sé as each row is the result of the crosstab query.
    What is the best way to offer the edit functionality using Apex?
    Thank,
    S>
    QUERY:
    SELECT vendor, product,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'JAN', amount, NULL)) AS JAN,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'FEB', amount, NULL)) AS FEB,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'MAR', amount, NULL)) AS MAR,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'APR', amount, NULL)) APR,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'MAY', amount, NULL)) MAY,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'JUN', amount, NULL)) JUN,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'JUL', amount, NULL)) JUL,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'AUG', amount, NULL)) AUG,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'SEP', amount, NULL)) SEP,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'OCT', amount, NULL)) OCT,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'NOV', amount, NULL)) NOV,
         MAX (DECODE (TO_CHAR(valuedate, 'MON'), 'DEC', amount, NULL)) DEC
    FROM (SELECT v.NAME AS vendor, p.NAME AS product, vt.NAME AS valuetype,
              e.datetime AS valuedate, e.VALUE AS amount
              FROM pfm_entry e, pfm_vendor v, pfm_product p, pfm_value_type vt
              WHERE e.vendor_route_id = v.route_id
              AND e.product_id = p.ID
              AND e.value_type_id = vt.ID
              AND e.value_type_id = 1
              AND e.datetime BETWEEN '01-JAN-07' AND '31-DEC-07')
    GROUP BY vendor, Product

    Hello, Steven
    Maybe you can use collections for that.
    Create a new collection which store your select statement.
    Each member of the collection have a unique id so you can use edit functionnality.
    And create a PL/SQL process which update your original table when the elements
    of your collection is updated.
    You can look at this doc. It may be useful.
    http://www.oracle.com/technology/oramag/oracle/06-nov/o66browser.html
    Mike

  • Help on performance with dynamic query

    Hi All,
      We are using SQL Server 2008R2. In our one of report we are using Dynamic query and it is taking more time to retrieve the data. to retrieve 32 records it is taking 13-15 secs. In my observation in a table variable, created more than 60 columns. In
    the SP called one more sp with insert statement.
    Please let me know how i can improve performance of the SP.
    I know that i have to provide the SP  for observation but unfortunately I cannot provide the SP. Please guide me how i can achieve this .
    I tried with temp tables by creating indexes on temp tables but i couldn't find improvement in performance. 
    Waiting for valuable replies.

    First of all a "dynamic query" is not "a query" - it is a multitude of them. Some of them may be fast, others may be slow.
    There is of course no way we can give specific suggestions without seeing the code, the table and index definitions etc.
    We can only give the generic suggestions. As for the code, make sure that you are using parameterised SQL and you are not building a complete SQL string with parameters and all. If nothing else, this helps to make the code more readable and maintainable.
    It also protects you against SQL injection. And it also helps to prevent performance issue due to implicit conversion.
    You will need to look at the query plan to see where the bottlenecks may be. You should look at the actual query plan. Note that the thickness of the arrows are more relevant than the percentages you see; the percentages are only estimates, and estimates
    are often off. Next step is to see if you can add indexes to alleviate the situation. You should also analyse if there are problems in the query, for instance indexed columns that are entangled in expression. If you are using views, make sure that you don't
    have views built on top of views etc. This can often result a table appearing multiple times in a query, when one would be enough.
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for

  • Comments Posting w/o scripting - Lost control over my JSP flow

    Hi all, Imagine you have a page where users can view comments from other users. And imagine that members can also post comments, but non-member guests can not. You want everyone to get the same page, but you want members to see more things on the pag

  • Macbook doesn't recognize Fitbit dongle

    I've lost two Fitbits Ultras that attach to your waist. I've gone back to the Flex. I'm trying to switch hardware and reinstall my Flex, however, the dongle is not being recognized. Any suggestions? 

  • Control Center status running scheduled jobs stops when DB is shutdown

    I have scheduled jobs in the Control Center of OWB, and the status is "Running" (Green Arrow ->), but everytime we stop and start the database I have to start the schedule job again under Status. Is there any way to fix this so that when the database

  • MacBook running 10.7.5  MacBook pro  10.4.11  Compatibility question?

    I have a macbook running 7.5  Just bought a used macbook pro that has 10.4.11  I called apple and bought a 10.6 update disk - it is about a week out due to shipping - I just backed up the macbook running 10.7.5  with carbon copy cloner I connected th

  • Problems to generate WSDL file

    Hello to all, I am adapting the sample ( /xws-security/samples/simple) to develop my service. When I compile the file WSDL no is adapted with my changes. I think that the problems is in build.xml, in gen-service target where execute wscompile to gene