APEX, BI Publisher and SQL Query (PL/SQL Function returning SQL Query)..

I don't know if I should be posting this in this Forum or the BI Publisher forum, so I am posting in BOTH forums..
I love APEX, let me say that first.. And appreciate the support offered here by the group, but am running int a confusing issue when BI Publisher tries to build a report from the above type APEX report..
Here is my dilemma:
I have a number of reports that are part of a Oracle package. They return an SQL Query back to a reports region on a page. I am having to deal with the column names returned are col01, col02..
The issue I have is, when building the Application Level query to download the XML sample from in building RTF layouts in Word, you can not use this code, you MUST use a standard SQL Select.
I have taken the sql from the function returning sql, and copied into the application query, supplying the required data values for bind variables being used in the query.
An XML file is produced, and I use this to build the RTF format file that I load back into APEX and try to use it for the PDF rendering of the report. I can view the output as a PDF in the Word add on, but when I try using it with the report, it is returning an empty PDF file.
Can anyone tell me what error log files on the bi publisher side I can look at to see what error is happening?
Thank you,
Tony Miller
UTMB/EHN
Title changed, maybe SOMEONE has an idea on this??
Message was edited by:
Tony Miller

Hi,
1/ first check you are passing the bind variables and
appropriate values in the call to your report - if
the query returns no data then you get an empty page
So if your query takes :P10_USERNAME variable then
pass it to the report in the URL
f?p=&APP_ID.:0:&SESSION.:PRINT_REPORT=YOUR_REP_QUERY_N
AME:::P10_USERNAME:MYUSER
2/ try to use the Default layout first to check your
report query really returns the data when called
3/ if you defined a header in your rtf template check
there is no & (ampersand) - if using & in the header
and preview the template from word it displays data
OK, but if you use this template in the report query
it fails to render the data (bug in Apex-> Bi
Publisher integration maybe?)
4/ If using the table in the rtf template check its
width does not overflow the page margins - there is a
problem with pdf export
5/ check
/oc4j/j2ee/home/application-deployments/xmlpserver/app
lication.log forthe information on BI Publisher runs
RadoIssue was in the APEX page having issues.. I recoded a new page and am able to generate BI Publisher based PDF files..
Thank you,
Tony Miller
UTMB/EHN

Similar Messages

  • On Submit process not firing -report (PL/SQL function returning SQL query)

    Can anyone suggest possible causes / solutions for the following problem?
    I have a report region that uses a PL/SQL function returning SQL query. The report allows the user to update multiple fields / rows and then click a button to submit the page which should run the On-Submit process to update the database. However the process does not run and I get a 'HTTP404 page cannot be found' error; and when I navigate back using the Back button I cannot then navigate to any other page in my application without getting the same error. The button was created by a wizard selecting the options to submit the page and redirect to a (same) page. The button does not actually have a redirect in its definition but the wizard created a branch to the same page which should work and the button has the text 'submit as SUBMIT' next to it so it appears to be set up correctly.
    I have recreated this page several times in my application and I cannot get the On-Submit process to run. However I have created a cut down version of the same page in the sample application on apex.oracle.com at http://apex.oracle.com/pls/otn/f?p=4550:1:179951678764332 and this works perfectly so I am at a loss to understand why it does not work in my application. I cannot post any part of the application itself but if anybody would like to check out page 30 of the sample application (Customer Update Test tab) updating the surnames only, using credentials ja, demo, demo this is pretty much what I have got in my application.
    Any ideas would be much appreciated?

    Thanks for the suggestions guys. I have now identified that the problem goes away when I remove the second table from my report query. The original report query retrieved data from two tables and the process was updating only one of the tables. I thought I had approached the task logically i.e. first get the report to display the records from the two tables, then get the process to update the first table and finally to modify the process further to update the second table.
    Can anyone point me to an example of multiple row updates on multiple tables using a PL/SQL function returning an SQL query?

  • Using 'Function Returning SQL Query' with Flash charts

    I have created a pl/sql function that returns a SQL query as a varchar2 of this form:
    select null link
    <x value> value
    <Series1 y value> Series 1 Label
    <Series2 y value> Series 2 Label
    <Series3 y value> Series 3 Label
    from tablea a
    join tableb b
    on a.col = b.col
    order by <x value>
    If I now call the function from a Flash Chart Series SQL box with the Query Source Type set to 'Function Returning SQL Query' like this:
    return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'))
    it parses correctly and the page is saved; however, when I run the page I don't get any output - nor any error messages or other indication of a problem.
    Now, if I call the function in a SQL client, capture the SQL query output using dbms_output and paste that into the Flash Chart Series SQL box - changing the Query Source Type to SQL Query - and save the page it works fine when I run it and returns a multi-series flash chart.
    Can anyone suggest either;
    1. What have I might have missed or done wrong?
    2. Any way to usefully diagnose the problem...
    I have tried using the Apex debugger - which is very nice, by the way - but it doesn't provide any info on what my problem might be. I even tried writing my own debug messages from my function using the apex_debug_message package - got nothing...
    Thanks,
    Eric

    Hi Eric,
    Try expressing the source as this:
    begin
       return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
    end;That works fine for me, and if I take out the begin-end and the trailing semicolon from the return statement I get the same behavior as you.
    It does mention in the help for the source (only during the wizard though) that this source type has to be expressed that way, but I agree it would be helpful if the tool would validate for this format when 'Function Returning SQL Query' is used or give some sort of indication of the trouble. Anyway, this should get you going again.
    Hope this helps,
    John
    If you find this information useful, please remember to mark the post "helpful" or "correct" so that others may benefit as well.

  • Interactive Report based on a function returning SQL query?

    Hi guys!
    I'm wondering if the IR based on a function returning SQL query will be available on the final release of APEX 4.0..I can't see this functionality in EA1 and EA2 and I think it should be there..dont you think?
    With regards,
    PsmakR

    Hi!
    You're absolutely sure you're talking about the Interactive Report region and not about the default SQL Report region ?
    With regards,
    PsmakR

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • SQL Query(PL/SQL Function Returning SQL Query)

    I am trying to write a dynamic report using SQL Query(PL/SQL Function Returning SQL Query).
    I can get the report to run but I need to concatinate some columns into one, seperated by a comma or a dash.
    I have tried select *****||','||***** alias
    also select *****||'-'||***** alias
    but I always get an error.
    Is there a way of doing this please
    Gus

    This is my full query
    declare
    v_query varchar2(4000);
    begin
    if :P63_TRAN_INFO = 2 THEN
    v_query := 'select
         A.FILENR,
         A.EXERCISENAME,
    A.STARTDATE,
    A.ENDDATE,
         A.UNIT,
    A.ACCADDRESSES, B.ADDRESS, B.ADDRESS_1, B.POST_CODE, B.TOWN,
         A.EXERCISEAREAS,
         A.TOTALVEHICLES,
    A.TOTALTROOPS+A.RNTOTALTROOPS+A.RAFTOTALTROOPS TOTALTROOPS,
    A.CAR, A.MINIBUS, A.HGV,
    A.NAMERANK, A.ADDRESS, A.ADDRESSI, A.ADDRESSII, A.POSTCODE,
    A.TRANSIT,
    A.INFOONLY
    from     BFLOG_AT A, BFLOG_ACCADDRESS B
    WHERE A.ACCADDRESSES = B.NAME
    AND A.STARTDATE >= :P63_START_DATE
    AND A.ENDDATE <= :P63_END_DATE
    AND A.AUTHORISED = 1
    AND A.INFOONLY = 1' ;
    END IF;
    RETURN v_query;
    END;
    This query runs ok, but if I try changing it to the code below with fields concatinated, then it fails
    declare
    v_query varchar2(4000);
    begin
    if :P63_TRAN_INFO = 2 THEN
    v_query := 'select
         A.FILENR,
         A.EXERCISENAME,
    A.STARTDATE,
    A.ENDDATE,
         A.UNIT,
    A.ACCADDRESSES||','||B.ADDRESS||','||B.ADDRESS_1||','||B.POST_CODE||','||B.TOWN ADDRESS,
         A.EXERCISEAREAS,
         A.TOTALVEHICLES,
    A.TOTALTROOPS+A.RNTOTALTROOPS+A.RAFTOTALTROOPS TOTALTROOPS,
    A.CAR, A.MINIBUS, A.HGV,
    A.NAMERANK, A.ADDRESS, A.ADDRESSI, A.ADDRESSII, A.POSTCODE,
    A.TRANSIT,
    A.INFOONLY
    from     BFLOG_AT A, BFLOG_ACCADDRESS B
    WHERE A.ACCADDRESSES = B.NAME
    AND A.STARTDATE >= :P63_START_DATE
    AND A.ENDDATE <= :P63_END_DATE
    --AND (A.EXERCISEAREAS LIKE "GAP, OA, OAL")
    --OR (A.EXERCISEAREAS LIKE "Harz")
    AND A.AUTHORISED = 1
    AND A.INFOONLY = 1' ;
    END IF;
    RETURN v_query;
    END;
    Cheers
    Gus

  • Column order in SQL Query (PL/SQL function returning a query)

    Hi,
    when I define a PL/SQL function returning a query inside a region, I often find that the column order is arbitrarily changed.
    How do I enforce the column order ?
    Bye,
    Flavio

    I removed the 11th column called service_name from this dynamic query: and now the report says: report error:
    ORA-01403: no data found. I messed around with the Headiuns Type. It was set to Custom. I changed it to Column Names. There is no difference.
    I am not sure how to fix?
    declare topqry varchar2(32000);
    whereqry varchar2(32000);
    finalqry varchar2(32000);
    var_status varchar2(100);
    division_status varchar2(50);
    office_status varchar2(1000);
    user_status varchar2(1000);
    overdue_status varchar2(1000);
    begin
    if :P10_FALLBACK = 'All' then
    var_status:= ' and vp.status in (''FA'',''FBA'',''FBI'',''25%'',''50%'',''90%'',''Closed'') ';
    elsif :P10_FALLBACK = 'Active' then
    var_status:= ' and vp.status in (''FA'',''25%'',''50%'',''90%'',''FBA'') ';
    elsif :P10_FALLBACK = 'FB' then
    var_status:= ' and vp.status in (''FBA'',''FBI'') ';
    elsif :P10_FALLBACK = 'Closed' then
    var_status:= ' and vp.status in (''Closed'') ';
    elsif :P10_FALLBACK = 'Inactive' then
    var_status:= ' and vp.status in (''FBI'') ';
    end if;
    if :P10_DIVISION = 'All' then
    division_status:= ' and vp.vms_division in (''News'',''Ad Services'') ';
    elsif :P10_DIVISION = 'News' then
    division_status:= ' and vp.vms_division in (''News'') ';
    elsif :P10_DIVISION = 'Ad' then
    division_status:= ' and vp.vms_division in (''Ad Services'') ';
    end if;
    if :P10_OFFICE = '%' then
    office_status:= ' and OFFICE_ID in (select office
    from VMS_OFFICE_ACCESS
    where user_id = lower(:P0_user) ) ';
    else
    office_status:= ' and OFFICE_ID in :P10_OFFICE ';
    end if;
    if :P10_LIMIT_USER = '%' then
    user_status := ' and SALESPERSON in (select first_name || '' '' || last_name
    from VMS_PROSPECT_users u
    join vms_office_access o
    on u.office_id = OFFICE
    where o.user_id = lower(:P0_USER) ) ';
    else
    user_status:= ' and SALESPERSON in (:P10_LIMIT_USER ) ';
    end if;
    if :P10_SHOW_OVERDUE = 'Show' then
    overdue_status:= ' and target_close_date <= sysdate ';
    var_status:= ' and vp.status in (''25%'',''50%'',''90%'',''FBA'') ';
    else
    overdue_status:= ' and FIRST_APPOINTMENT between
    nvl(to_date(:P10_FIRST_APPT_START, ''mm/dd/yyyy''),FIRST_APPOINTMENT) and
    nvl(to_date(:P10_FIRST_APPT_END,''mm/dd/yyyy''),FIRST_APPOINTMENT) ';
    end if;
    topqry := 'SELECT OFFICE_ID ,vp.PROSPECT_ID ,ENTRY_DATE ,ACCOUNT , NEXT_CONTACT_DATE ,ACTION_STEP ,
    TARGET_CLOSE_DATE ,vp.STATUS ,SALESPERSON ,vp.SALES_TYPE ,service_name , FIRST_APPOINTMENT ,MODIFY_DATE ,EST_ANNUAL_REVENUE ,EST_INCREMENTAL_REVENUE ,
    pi.NOTES , pi.SALES_TYPE ,pi.STATUS ,Contact ,Origin_Source FROM VMS_PROSPECTING_ITEMS pi right outer join VMS_PROSPECTS vp on vp.PROSPECT_ID = pi.PROSPECT_ID left outer join VMS_SERVICES vs on vs.service_ID = pi.service_ID where 1 = 1 ';
    whereqry := ' and (not exists (select *
    from VMS_PROSPECTING_ITEMS i3
    where vp.prospect_id = i3.prospect_id)
    or exists (select *
    from VMS_PROSPECTING_ITEMS i2
    where i2.order_id = pi.order_id
    and active = ''Y'' )) and instr(upper(ACCOUNT),upper(nvl(:P10_ACCOUNT,ACCOUNT))) > 0 ';
    whereqry := whereqry || var_status || division_status || office_status || user_status || overdue_status;
    finalqry := topqry || whereqry;
    return finalqry ;
    end;

  • Issue with running PL/SQL function returning Sql query

    hi, I am trying to create a report region by using the option of PL/SQL function returning sql query.
    I notice that it's very slow for the report region page to show up. In my PL/SQL function body, there are only 3 steps, first update all the 10 rows of varchar2 fields to null,then insert values to those fields, then select all from the table to show report results. It takes more than 5 minitues for the page to load up, how ever, if i run those steps in SQL*Plus, it only takes a couple of seconds to finish. Any suggestions?
    Thanks,
    gina

    Sergio, the codes are as followed,
    Declare
    q varchar2(32767); -- query
    Begin
    q := 'select "ID",'||
    '"ENTRY NAME","TOTAL","#CM","%CM","#CA",'||
    '"%CA", from Info_table';
    update info_table
    set "TOTAL" = '',
    "#CM" = '',
    "%CM" = '',
    "#CA" ='',
    "%CA"=''
    where "ID"<=10;
    // set all data in column Total to null,there is only 10 rows in the table
    update info_Table set Total = vTotal,
    "#CM" = vCM
    (those variables hold user key-in Text filed value)
    where ID = 1;
    return q;
    End;

  • Function Returning SQL in BI Publisher Report Query

    I have a report that is based on a SQL Query (PL/SQL Function body returning SQL query). The code is below. I am now trying to create a PDF version of the report using BI Publisher in APEX. When I try to build the Report Query shared component I get a syntax error when entering this code. Does anyone know if it is possible to create a Report Query from a SQL Query (PL/SQL Function body returning SQL query) and if so, how?
    v_sql varchar2(4000);
    begin
    select apexim.exec_summ_bymonth_sql ('D', :p260_time_frame, 12, nvl(:p260_population_sel, 'All'), nvl(:p260_region_sel, 'All'), nvl(:p260_oper_state_sel, 'All'))
    into v_sql
    from dual;
    return(v_sql);
    end;.

    Thanks for the suggestion Simon.
    I just created a view based on the 46-column SELECT statement from dual above and then set "SELECT * FROM myview" as the Source Query.
    Unfortunately I get exactly the same error.
    Thanks,
    Andy

  • Conditional display of region with PL/SQL function returning SQL query

    Hello,
    ApEx 2.0.
    I use PL/SQL functions that return SQL queries to display the contents of a region.
    How could I conditionally display such region ? If no data is found, the region shouldn't be shown. I tried with "SQL query returns at least one row" but this doesn't seem to work.
    Thanks,
    Matthias

    Hi Matthias,
    Are the regions in question report regions? So your PL/SQL process is returning a SQL query and then populating a report?
    The EXISTS(SQL Query returns at least one row) condition should work, try running the query you are using in the Expression 1 textarea inside SQL*Plus, or SQL developer using the same parameters, and see what gets returned.
    If you are still stuck, can you post the query you are using inside your Expression 1 textarea of the Conditions section and I can take a look at it for you.
    Hope this helps,
    Cj

  • Function returning SQL query for mutiple series in a chart

    Hi,
    I would like to know if there is a way to specify a single PL/SQL function returning the queries for multiple series in a 2D Line Flash Chart. I have multiple series in my chart that has different values in the where clause. I can write a PL/SQL function that can return all these queries in one shot. Is there anyway that I can specify this function as returning the queries for all the series in the chart?
    As an example, assume that I am using the following three queries for the series in my chart:
    select deptno, count(*) from emp where deptno = 10 group by deptno
    select deptno, count(*) from emp where deptno = 20 group by deptno
    select deptno, count(*) from emp where deptno = 30 group by deptno
    I can't write a PL/SQL function that returns a query in the multiple series syntax (SELECT link, label, series_1_value [, series_2_value [, ...]]FROM ...) as I am using an aggregate function and my where clause is different for each series.
    Thanks,
    Rupesh

    Hi Roel,
    Thanks for your reply. I am already using an analytical function (RATIO_TO_REPORT(COUNT(*)) OVER () ) in my actual report. My problem is that the query for one series differs from the other only in one where clause. I will be able to dynamically able to generate all the queries for all the series in one pl/sql function. But the chart definition screen does not allow us to define a single function that returns queries for the all the series - possibly seperated by some seperator like S1: select.... S2:select and so on.
    Regards,
    Rupesh

  • Function returning a query

    Hi guys,
    A query suddenly became very slow & has remained like it while connecting over a database. I assume the reason is because the data is being retrieved from 6 tables across a link (6 different connections to the same database) so I thought a view should be better as I had a similar issue and this seemed to resolve it. However I then thought that perhaps a function returning the results would be faster as it would mean I could include the where clauses & group by clause to be done remotely on the database rather than locally after much more rows were returned...is this assumption correct?
    My query is as follows:
    select     rpad(username,18) user_name, rpad(terminal,18) terminal_id, rpad(userhost,30) host_name, 
               action_name, count(*) actions, sum(sessioncpu) session_cpu
    from
    select     username,
       terminal,
       userhost,
       action_name,
       to_char(timestamp,'DD/MM/YYYY HH24:MI:SS') timestamp,
       logoff_time,
       returncode, session_cpu sessioncpu
    from       dba_audit_session@XXX
    where (logoff_time >= sysdate - :P1_RAD
    AND :P1_RAD IS NOT NULL AND :P1_RAD != -1
    AND :REQUEST != 'But')
    OR (logoff_time >= to_TIMESTAMP(TO_DATE(:P1_FROM, 'DD-MON-YY') || ' ' || :P1_FROM_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND logoff_time < to_TIMESTAMP(TO_DATE(:P1_TO, 'DD-MON-YY') || ' ' || :P1_TO_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND :REQUEST = 'But'
    AND :P1_FROM IS NOT NULL AND :P1_TO IS NOT NULL)
    union
    select username,
            terminal,
       userhost,
       action_name,
       to_char(timestamp,'DD/MM/YYYY HH24:MI:SS') timestamp,
       logoff_time,
       returncode, sessioncpu
    from
    select
           userid            USERNAME ,
           userhost          USERHOST ,
           terminal          TERMINAL ,
           cast (
               (from_tz(ntimestamp#,'00:00') at local) as date) timestamp,
           act.name          ACTION_NAME ,         
           logoff$time logoff_time      /* LOGOFF_TIME   */,
           sessionid         /* SESSIONID */,
           returncode        /* RETURNCODE */,      
           sessioncpu        /* SESSION_CPU */      
    from sys.aud_archive@XXX aud, system_privilege_map@XXX spm, system_privilege_map@XXX spx,
         STMT_AUDIT_OPTION_MAP@XXX aom, audit_actions@XXX act
    where   aud.action#     = act.action    (+)
      and - aud.logoff$dead = spm.privilege (+)
      and   aud.logoff$dead = aom.option#   (+)
      and - aud.priv$used   = spx.privilege (+)
    and act.action between 100 and 102
    where (logoff_time >= sysdate - :P1_rad
    AND :P1_RAD IS NOT NULL AND :P1_RAD != -1
    AND :REQUEST != 'But')
    OR (logoff_time >= to_TIMESTAMP(TO_DATE(:P1_FROM, 'DD-MON-YY') || ' ' || :P1_FROM_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND logoff_time < to_TIMESTAMP(TO_DATE(:P1_TO, 'DD-MON-YY') || ' ' || :P1_TO_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND :REQUEST = 'But'
    AND :P1_FROM IS NOT NULL AND :P1_TO IS NOT NULL)
    group by username,   terminal,   userhost,    action_name
    order by actions desc;So it would take 6 parameters (p1_rad, request, p1_from, p1_to, p1_from_hour, p1_to_hour) and return a table with 8 columns. Would the WHERE & GROUP BY clauses being done remotely rather than on APEX be much better?
    Mike

    In general functions don't help much to increase the performance.
    However sometimes you can programatically choose different select statements depending whether a parameter is filled by the user or not. This allows you as a programmer to provide different and optimized statements depening on the input conditions.
    simplified pseudocode example
    "SELECT"
    select *
    from myTable
    where (column1 = :param1 or :param1 is null); /* problematic to get an index scon on column1 for this OR expression */
    "PL/SQL"
    if :param1 is null then
      select *
      bulk collect into ...
      from myTable; /* Full table scan will be used */
    else
      select *
      bulk collect into ...
      from myTable
      where column1 = :param1; /* index scan on column1 can be used, column historgrams will be considered */
    end if;

  • Maximum length of query string for functions return a SELECT

    Hi all,
    I have a report that gets it's SELECT statement from a function, instead of being coded into the region. All was well but I suspect now I'm blowing some kind of limit as I'm getting an error :
         ORA-06502: PL/SQL: numeric or value error
         Error      ERR-1101 Unable to process function body returning query.
    However if I run the procedure out of ApEx and grab the SELECT statement then it works fine. The length of the query is 8636 bytes (yup, it's a beauty!).
    Does anyone know if there is a hard limit to the size of the string that can be returned?
    I'm using ApEx 3.1.
    Thanks,
    Steve H

    I do have a similar painfull scenario - Although my query length is very less i.e 618 bytes only.
    I have defined a stored function, which returns an SQL query string, this return SQL string executes fantastic but when I tried to to call this function from a APEX report it gives error. the details are as follows. Please help.......
    The function code:
    CREATE OR REPLACE function PROD."TEST_C_QRY"
    return VARCHAR2
    is
    msql VARCHAR2(32767);
    Begin
    msql:='Select null,statusname,AgeInd, ';
    For m_stat in (select statusname from a02_status)
    loop
    msql:= msql || q'[decode(statusname,']';
    msql:= msql || m_stat.statusname;
    msql:= msql || q'[',count(id),0) ]';
    msql:= msql || m_stat.statusname|| ',';
    end loop;
    msql:=rtrim(msql,',');
    msql:= msql||' from ';
    msql:= msql||'( ';
    msql:= msql||'select a.id, round(sysdate-a.registeredon) TimeSpan,';
    msql:= msql||'case ';
    msql:= msql||q'[when round(sysdate-a.registeredon)<=7 then 'Week' ]';
    msql:= msql||q'[when round(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' ]';
    msql:= msql||q'[when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then 'Month' ]';
    msql:= msql||q'[else 'More...'  end ageind,]';
    msql:= msql||'a.status_id,b.statusname ';
    msql:= msql||'from a02_task a,a02_status b ';
    msql:= msql||'where b.id=a.status_id) ';
    msql:= msql||'group by statusname,AgeInd;';
    return msql;
    end TEST_C_QRY;
    The Output SQL comes from this is
    SQL> Select null,statusname,AgeInd, decode(statusname,'Scheduled',count(id),0) Scheduled,decode(statusname,'Executing',count(id),0) Executing,decode(statusname,
    'Completed',count(id),0) Completed from ( select a.id, round(sysdate-a.registeredon) TimeSpan, case when round(sysdate-a.registeredon)<=7 then 'Week' when round
    (sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then
    'Month' else 'More...' end ageind, a.status_id,b.statusname from a02_task a,a02_status b where b.id=a.status_id) group by statusname,AgeInd;
    The result that comes when I execute the above resultant SQL is as follows.
    N STATUSNAME AGEIND SCHEDULED EXECUTING COMPLETED
    Completed More... 0 0 4
    Completed Week 0 0 1
    Scheduled Week 1 0 0
    Completed Month 0 0 3
    Executing More... 0 1 0
    Executing Month 0 6 0
    Scheduled More... 1 0 0
    7 rows selected.
    But the surprising error that comes from Oracle XE when I use the following code for stacked bar chart
    Code:
    begin
    return TEST_D_QRY;
    end;
    Error thrown by XE report builder is as follows:
    1 error has occurred
    Failed to parse SQL query!
    Select null,statusname,AgeInd, decode(statusname,'Scheduled',count(id),0) Scheduled,decode(statusname,'Executing',count(id),0) Executing,decode(statusname,'Completed',count(id),0) Completed from ( select a.id, round(sysdate-a.registeredon) TimeSpan, case when round(sysdate-a.registeredon)<=7 then 'Week' when round(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then 'Month' else 'More...' end ageind, a.status_id,b.statusname from a02_task a,a02_status b where b.id=a.status_id) group by statusname,AgeInd;
    Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
    Regards,
    Soumen

  • Dynamic LOV - Function returning LOV query

    Hi All,
    For some reason I can not write a generic LOV query and want to edit where clause dynamically. Is there a way to achieve it.
    My LOV query will be
    'SELECT D,R FROM LOV WHERE ID IN (1,2,3)' for one person and
    'SELECT D,R FROM LOV WHERE ID IN (4,5,6)' for another person.
    Here entire string "1,2,3" or "4,5,6" is from a page item say :P1_ID_LIST and I can not use the bind variable like 'SELECT D,R FROM LOV WHERE ID IN (:P1_ID_LIST)'.
    If I have the option of function returning the LOV query I can use
    return 'SELECT D,R FROM LOV WHERE ID IN (' || :P1_ID_LIST || ')'
    Does there a way to acheive in Apex?
    Thanks
    Balaji

    See Re: Search on a typed in list of values for at least part of the answer.
    Scott

  • Interactive report - Function returning SQL query

    i notice that it is not possible to create an interactive report based on a function call. can anyone shed any light on why this is?
    also, is there a work around possible? i really dont want to store my SQL query inside a page in the application

    Craig,
    I tried the collection workaround as well but noticed that it gets incredible slow when data sets grow bigger. Depending on what you need maybe my solution is of help for you:
    I used multiple subpages with interactive reports, an iframe and a javascript function setting the iframe-src on the main page, see my last post on
    interactive report custom GO-Button (-process)
    Paul

Maybe you are looking for