EncounteringERR-1101 Unable to process function body returning query

hi,
I am new to APEX and finding some difficulties while developing an application. My application chooses a value from a dropdown, and depending on the value chosen, adds some columns in the report.
The code is somewhat like below:
DECLARE
--variable declaration for col headers for ports
l_p_name ports_ver.port_name%TYPE;
l_id ports_ver.port_id%TYPE;
type pstr is varray(25) of varchar2(100);
nm pstr;
hdr varchar2(1000);
chd varchar2(100);
msg varchar2(6000);
msg1 varchar2(6000);
h varchar2(60);
begin
l_p_name := :PR_VALUE; ----the dropdown value
msg := 'select 1 "Edit" , p.ID "ID",p.TEST_MANAGER "Manager",p.AREA_NAME "Area", p.COMPONENT "Component", v.port_name "Port",';
select version
bulk collect into nm
from ports_ver
where port_name=l_p_name;
for i in nm.first..nm.last
loop
select get_col_head(l_p_name,nm(i)) into hdr from dual;
chd := 'Tstng Pltfrm '||nm(i);
msg := msg||' hdr "'|| chd ||'", ';
--msg1 := msg || 'null, ';
end loop;
msg1:= msg || 'p.imp_blk_bug "Blocking Bugs" , p.NUM_SCENARIOS "No of Scenarios" ,p.PASS "Pass", p.FAIL "Fail" ,p.COMPLETE "Complete" ,p.COMMENTS "Comment" ,v.version "VERSION" from PORT_FFT p,ports_fft_sts s ,ports_ver v
where v.port_name = l_p_name ;';
return msg1;
end;
can you point me some hints?

Hi, and welcome!
Firstly, you don't need to end the SQL statement with a semi-colon as you are returning a SQL query rather than PL/SQL code. So, change:
where v.port_name = l_p_name ;';to:
where v.port_name = l_p_name';Your SQL statement itself uses three tables, yet your WHERE clause only references two - is this intentional?
Andy

Similar Messages

  • Unable to process function body returning query

    I have a table called ACCESS. The table has two columns, PERSON_ID NUMBER (holds employee reference) and SQL_QUERY VARCHAR2(4000) (holds query 'SELECT COL1, COL2, COL3 FROM APEX_TABLE;' )
    I am in the process of generating SQL Report. In the Create SQL Report (Page > SQL Report >Create SQL Report),
    I want to dynamically fetch the SQL_QUERY from the ACCESS table something like the below one.
    DECLARE
    strSql VARCHAR2(4000);
    BEGIN
    SELECT SQL_QUERY INTO strSql FROM ACCESS WHERE PERSON_ID=100;     
    RETURN strSql;
    END;
    I get the error Unable to process function body returning query when I try to run the page.
    However if I hardcode the query in the PL/SQL block, it works for example:
    DECLARE
    strSql VARCHAR2(4000);
    BEGIN
    strSql := 'SELECT COL1, COL2, COL3 FROM APEX_TABLE';
    RETURN strSql;
    END;
    How to resolve this?
    Regards,
    Anand

    Hi Denes,
    In your demo application you are using the below query (function returning sql). Is it possible to store this query as VARCHAR2 in a database table and query the table to return the QUERY ('SELECT deptno....')? Can you explain me with an example?
    DECLARE
    q VARCHAR2 (1000);
    BEGIN
    q := q || 'SELECT deptno, DECODE(deptno, ';
    q := q || '10, ''<img src="#IMAGE_PREFIX#bullet1.gif" >'', ';
    q := q || '20, ''<img src="#IMAGE_PREFIX#bullet2.gif" >'', ';
    q := q || '30, ''<img src="#IMAGE_PREFIX#bullet3.gif" >'', ';
    q := q || '40, ''<img src="#IMAGE_PREFIX#bullet4.gif" >'') ';
    q := q || 'image, dname FROM DEPT ';
    q :=
    q
    || 'WHERE CASE WHEN TO_NUMBER (:p1_dept) != -1 THEN deptno '
    || 'ELSE 1 END = CASE WHEN TO_NUMBER (:p1_dept) != -1 '
    || 'THEN TO_NUMBER (:p1_dept) ELSE 1 END';
    RETURN q;
    END;
    Thanks
    Anand

  • Kindly help ORA-00917: missing comma" ERR-1101 Unable to process function

    HI Experts,
    Since yesterday every thing was fine, i do not know what happened in the evening, we are facing some issue with our production.
    I'm getting the following error ,when i running the report
    ORA-00917: missing comma
         Error      ERR-1101 Unable to process function body returning query.
    Since long time we have even not touched the code , i'm wondering about this error...the same code was working fine just 2 days back.
    Kindly help me with this...
    Code
    DECLARE
       date_from DATE:=:P46_TRANS_DATEFROM;
       date_to DATE:=:P46_TRANS_DATETO;
       --date_from DATE :=TO_DATE('22-Nov-2007','DD-Mon-yyyy');
       --date_to DATE :=TO_DATE('23-Nov-2007','DD-Mon-yyyy');
       date_counter DATE:=date_from;
       v_city varchar2(32):=:P46_CITY;
       str_month1 VARCHAR2(3):=SUBSTR(TO_CHAR(date_from,'DD-MON-YYYY'),4,3);
       str_year1 VARCHAR2(4):=SUBSTR(TO_CHAR(date_from,'DD-MON-YYYY'),8,4);
       str_month2 VARCHAR2(3):=SUBSTR(TO_CHAR(date_to,'DD-MON-YYYY'),4,3);
       str_year2 VARCHAR2(4):=SUBSTR(TO_CHAR(date_to,'DD-MON-YYYY'),8,4);
       day_from VARCHAR2(2):=SUBSTR(date_from,1,2);
       day_to VARCHAR2(2):=SUBSTR(date_to,1,2);
       CURSOR trans_alloc(m VARCHAR2,y NUMBER,email VARCHAR2) IS SELECT * FROM EFT_TRANS_ALLOCATION WHERE LOWER(MONTH)=LOWER(m) AND YEAR=y AND LOWER(email_id)=LOWER(email);
       CURSOR trans_schedules(m1 VARCHAR2,y1 NUMBER,m2 VARCHAR2,y2 NUMBER) IS SELECT * FROM OD_SHIFT_SCHEDULE WHERE (UPPER(MONTH)=m1 OR UPPER(MONTH)=m2) AND (YEAR=y1 OR YEAR=y2);
       CURSOR get_res_id(email VARCHAR2) IS SELECT resource_id,first_name,last_name FROM EFT_RESOURCES WHERE LOWER(email_id)=LOWER(email);
       rec OD_SHIFT_SCHEDULE%ROWTYPE;
       CURSOR get_shifts(id VARCHAR2) IS SELECT * FROM OD_SHIFTS WHERE shift_id=id;
       ta EFT_TRANS_ALLOCATION%ROWTYPE;
       sd OD_SHIFTS%ROWTYPE;
       sql_str VARCHAR2(4000);
       v_res_id NUMBER;
       v_fname VARCHAR2(50);
       v_lname VARCHAR2(50);
       v_shift_id VARCHAR2(32);
       s VARCHAR2(1000);
       d VARCHAR2(32);
       final_sql VARCHAR2(4000);
       v_consent VARCHAR2(3);
       s2 VARCHAR2(1000);
       dn DATE;
    BEGIN
       DELETE FROM EFT_SHIFT_SCHEDULES_RPT;
       OPEN trans_schedules(UPPER(str_month1),TO_NUMBER(str_year1),UPPER(str_month2),TO_NUMBER(str_year2));
       LOOP
          FETCH trans_schedules INTO rec;
           EXIT WHEN trans_schedules%NOTFOUND;
           OPEN get_res_id(rec.name);
           FETCH get_res_id INTO v_res_id,v_fname,v_lname;
              OPEN trans_alloc(TO_CHAR(date_counter,'MON'),TO_NUMBER(TO_CHAR(date_counter,'YYYY')),rec.name);
               FETCH trans_alloc INTO ta;
               IF trans_alloc%FOUND THEN
               dbms_output.put_line (date_counter||'----'||date_to||'Res_id:----'||v_res_id||'-'||ta.slno);
               dbms_output.put_line ('Found Alloc');
               WHILE date_counter<=date_to
               LOOP
                    --d:=d||'-'||str_month||'-'||str_year;
                    d:=SUBSTR(TO_CHAR(date_counter,'DD-MON-YYYY'),1,2);     
                    s:='INSERT INTO temp_2 SELECT "'||d||'" from OD_SHIFT_SCHEDULE where slno='||rec.slno;
                    --dbms_output.put_line (d||'-'||s);
                    DELETE FROM temp_2;
                    EXECUTE IMMEDIATE s;
                    SELECT substr(trim(VAL),1,1) INTO v_shift_id FROM temp_2;
                    s2:='INSERT INTO temp_3 SELECT "'||d||'" from EFT_TRANS_ALLOCATION where slno='||ta.slno;
                    DELETE FROM temp_3;
                    EXECUTE IMMEDIATE s2;
                    SELECT VAL INTO v_consent FROM temp_3;
                    --dbms_output.put_line (v_shift_id||'-'||v_consent);
                    --dbms_output.put_line (date_counter||'-'||date_to);
                    IF v_consent='Y' THEN
                    --dbms_output.put_line ('Im inside consent'||v_consent);
                    IF v_shift_id IS NOT NULL THEN
                    --dbms_output.put_line ('Im inside shift not null'||v_shift_id);
                       OPEN get_shifts(v_shift_id);
                       FETCH get_shifts INTO sd;
                        IF sd.night_shift_indicator='Y' THEN
                           dn:=date_counter+1;
                        sql_str:='INSERT INTO eft_shift_schedules_rpt VALUES ('||v_res_id||','''||v_fname||''','''||v_lname||''','''||rec.name||''','''||sd.shift_name||''','''||date_counter||''','''||sd.start_from||''','''||sd.start_to||''','''||''','''||sd.active_yn||''','''||dn||''')';
                        ELSE
                           sql_str:='INSERT INTO eft_shift_schedules_rpt VALUES ('||v_res_id||','''||v_fname||''','''||v_lname||''','''||rec.name||''','''||sd.shift_name||''','''||date_counter||''','''||sd.start_from||''','''||sd.start_to||''','''||''','''||sd.active_yn||''','''||date_counter||''')';
                        END IF;
                       EXECUTE IMMEDIATE sql_str;
                       CLOSE get_shifts;
                        --dbms_output.put_line (sql_str);
                    END IF;
                    END IF;
                    COMMIT;
                    date_counter:=date_counter+1;     
              END LOOP;
               END IF;
          CLOSE trans_alloc;
           CLOSE get_res_id;
           --dbms_output.put_line (rec.name);
           date_counter:=date_from;
       END LOOP;
       COMMIT;
       CLOSE trans_schedules;
    final_sql:='select a.first_name,a.last_name,a.email_id,a.shift_details,a.arrange_date,a.slot_from,a.slot_to,a.trans_arranged,a.active_yn,b.address1,b.address2,b.city,b.state,b.pin,b.worknumber,b.homenumber,b.mobilenumber,a.to_date from eft_shift_schedules_rpt a,eft_locations b where a.resource_id=b.resource_id and b.city =:P46_CITY';
    --dbms_output.put_line (final_sql);
    RETURN final_sql;
    END;

    Hi Basva,
    my best advice is find out where the error happens, e.g. using DBMS_UTILITY.FORMAT_ERROR_BACKTRACE .
    In the next step you can fix the error and rework the code so that it looks nice and has some comments in it so everyone knows what it SHOULD do.
    brgds,
    Peter
    Blog: http://www.oracle-and-apex.com
    ApexLib: http://apexlib.oracleapex.info
    BuilderPlugin: http://builderplugin.oracleapex.info
    Work: http://www.click-click.at and http://www.wirsindapex.at

  • SQL Query ( PL/SQL function body returning query ) page

    Hello Friends,
    I have a page with type SQL Query ( PL/SQL function body returning query ).
    I have written a pl/sql block that returns a sql query - select statment.
    Some times i am getting no data found error - does it got to do with the variable that stores the query .
    =======================
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Error ERR-1101 Unable to process function body returning query.
    OK
    =====================
    When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
    Here's the pl/sql block ..
    The query is generated while the user is navigating through pages ..
    ====================
    declare
    l_return_stmt varchar2(32767);
    l_select varchar2(32000);
    l_from varchar2(32000);
    l_where varchar2(32000);
    l_order_by varchar2(32000);
    l_stmt_recordcount varchar2(32000);
    l_recordcount number ;
    begin
    l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
    ||:P10_VARLIST4||:P10_VARLIST5;
    l_from := ' from '||:P10_RELATION;
    if length(:P10_WHERE) > 0 then
    l_where := ' where '||:P10_WHERE;
    else
    l_where := '';
    end if;
    if length(:P10_ORDER_BY) > 0 then
    l_order_by := ' order by '||:P10_ORDER_BY;
    else
    l_order_by := '';
    end if;
    l_return_stmt := l_select||l_from||l_where||l_order_by;
    :P10_STMT := l_return_stmt;
    return l_return_stmt;
    end;
    =============================
    Appreciate your help in this regard.
    thanks/kumar
    Edited by: kumar73 on Apr 22, 2010 6:38 AM

    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?

  • Function Body Returning Query -  Questioning my Approach

    Application Express 3.2.0.00.27
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    I have some concerns that I am not using this in the optimal manner.
    Essentially I have all my queries in a package body and I call each report as follows:
    declare
    v_query varchar2(4000);
    begin
    v_query := apex.report_name(p1=>   :page_item_1,
                                                  p2=>   :application_item2);
    return 'select * from ('|| v_query||' )';
    end;I then generate the string in the report_name procedure
    and concatenate the string.
    This results in a valid sql string being returned to the database , however if I pass a different value
    then I will get a different sql string.
    I would rather be able to use bind variables using this approach if at all possible.
    So is this the correct approach is there a better approach?
    Edited by: Keith Jamieson on Jan 18, 2012 12:50 PM
    Edited by: Keith Jamieson on Jan 18, 2012 1:40 PM

    Current project makes extensive use of packages containing Function Body Returning Query report sources to dynamically build queries from SQL modules. However, the queries generated by any function are all used within one page. This enables page item bind variable references to be fixed within the SQL:
    function emp (p_commission in number) return varchar2
    is
      q_emp_qry varchar2(4000) := q'{select * from emp where 1 = 1 }';
      k_has_comm constant varchar2(2000) := q'{and comm >= to_number(:p2_sales_comm)}';
    begin
      if p_commission is not null
      then
        q_emp_qry := q_emp_qry || k_has_comm;
      end if;
      return q_emp_qry;
    end emp;

  • SQL query (pl/sql function body returning query) performance issue

    I create my report in building my sql instruction with ( SQL Query pl/sql function body returning sql query );
    My report take more than 20 seconds however if i did a cut and paste with the sql code in TOAD the same sql take 1 second.
    To try to discover the source of the problem; i take the sql generated by the function and i create another report ( sql query ) this new report take 2 seconds.
    My query is very big 25,000 characters with database link.
    What is the difference between SQL-quey and sql-query(pl/sql function body returning sql query)
    Thanks
    Marc

    Marc,
    Firstly...don't compare the timings from Toad, since often Toad only fetches the first few records for you (i.e. it pages them).
    Secondly....the database link could be a factor here, but without seeing your query it's too hard to say.
    Can you post the query somewhere (on a webserver say)?

  • Report pl/sql function body returning query bind variable

    I really like using report with a function returning sql. I have been using something like this
    declare
    q varchar2(10000);
    begin
    q := 'select col1
    from mytable
    .... add a dynamic where clause ....
    return q;
    end;
    But I thought it would be nice to store the query in a bind variable so that I could show the where clause. I tried to create an item P123_Q and do the following:
    declare
    q varchar2(10000);
    begin
    q := 'select col1
    from mytable
    .... add a dynamic where clause ....
    :P123_Q := q;
    return q;
    end;
    But the parser treats :P123_Q as if it is a bind variable within flow 4000. I found a workaround but I'm wondering if there is a better way.
    My workaround is to set a preference in the query and then use a computation that sets P123_Q to the value of the preference:
    declare
    q varchar2(10000);
    begin
    q := 'select col1
    from mytable
    .... add a dynamic where clause l_q := l_q || ....
    HTMLDB_UTIL.SET_PREFERENCE(
    p_preference => 'Q',
    p_value => q,
    p_user => :APP_USER);;
    return q;
    end;
    Any thoughts on another way?
    thanks,
    Anton

    Anton,if htmldb_application.get_current_flow_sgid(:APP_ID) = htmldb_application.get_sgid then
      :P1_X := l_sql;
    end if;Scott

  • SQL Query (pl/sql function body returning Sql query)

    Hi All,
    I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
    It gives error for this region :
    Error ERR-1101 Unable to process function body returning query.
    OK
    ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
    Any pointer ...why this is happening.
    Thanks
    Dikshit

    If your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
    If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
    Let me know how you get on
    Regards
    Duncan

  • PL/SQL function body returning SQL query - ORA-06502: PL/SQL: numeric or value error

    I'm attempting to dynamically generate a rather large SQL query via the "PL/SQL function body returning SQL query" report region option.  The SQL query generated will possibly be over 32K.  When I execute my page, I sometimes receive the "ORA-06502: PL/SQL: numeric or value error" which points to a larger than 32K query that was generated.  I've seen other posts in the forum related to this dynamic SQL size limitation issue, but they are older (pre-2010) and point to the 32K limit of the DNS (EXECUTE IMMEDIATE) and DBMS_SQL.  I found this post (dynamic sql enhancements in 11g) which discusses 11g no longer having the 32K size limitation for generating dynamic SQL.  Our environment is on 11gR2 and using ApEx 4.2.1.  I do not know which dynamic SQL method -- DNS or DBMS_SQL -- ApEx 4.2.1 is using.  Can someone clarify for me which dynamic SQL method ApEx uses to implement the "PL/SQL function body returning SQL query" option?
    As a test, I created a page on apex.oracle.com with a report region with the following source:
    declare
      l_stub varchar2(25) := 'select * from sys.dual ';
      l_sql  clob := l_stub || 'union all ';
      br     number(3) := 33;
    begin
      while length ( l_sql ) < 34000 loop
        l_sql := l_sql || l_stub || 'union all ';
      end loop;
      l_sql := l_sql || l_stub;
      for i in 1 .. ceil ( length ( l_sql ) / br ) loop
        dbms_output.put_line ( dbms_lob.substr ( l_sql, br, ( ( i - 1 ) * br ) + 1 ) );
      end loop;
      return l_sql;
    end;
    The dbms_output section is there to be able to run this code in SQL*Plus and confirm the size of the SQL is indeed larger than 32K.  When running this in SQL*Plus, the procedure is successful and produces a proper SQL statement which can be executed.  When I put this into the report region on apex.oracle.com, I get the ORA-06502 error.
    I can certainly implement a work-around for my issue by creating a 'Before Header' process on the page which populates an ApEx collection with the data I am returning and then the report can simply select from the collection, but according to documentation, the above 32K limitation should be resolved in 11g.  Thoughts?
    Shane.

    What setting do you use in your report properties - especially in Type and in Region Source?
    If you have Type="SQL Query", then you should have a SELECT statement in the Region Source. Something like: SELECT .... FROM ... WHERE
    According to the ERR-1101 error message, you have probably set Type to "SQL Query (PL/SQL function body returning SQL query)". In this situation APEX expects you to write a body of a PL/SQL function, that will generate the text of a SQL query that APEX should run. So it can be something like:
    declare
    mycond varchar2(4000);
    begin
    if :P1_REPORT_SEARCH is not null THEN
    mycond:='WHERE LAST_NAME like :P1_REPORT_SEARCH ||''%''';
    end if;
    return 'select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from EMPLOYEES ' ||mycond;
    end;
    And for escaping - are you interested in escaping the LIKE wildcards, or the quotes?
    For escaping the wildcards in LIKE function so that when the user enters % you will find a record with % and not all functions, look into the SQL Reference:
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm
    (You would than need to change the code of your function accordingly).
    If you are interested in escaping the quotes, try to avoid concatenating the values entered by the user into the SQL. If you can, use bind variables instead - as I have in my example above. If you start concatenating the values into the text of SQL, you are open to SQLInjection - user can enter anything, even things that will break your SQL. If you really need to allow users to choose the operator, I would probably give them a separate combo for operators and a textfield for values, than you could check if the operator is one of the allowed ones and create the condition accordingly - and than still use bind variable for inserting the filtering value into the query.

  • Multiple Select List looping thru PL/SQL function body returning SQL query

    Hi,
    I have a Multiple Select List. I want to loop through the values from the Select List and process them in a PL/SQL function body returning a SQL query. Currently, my code only returns the SQL SELECT results of one item in the select list. How do I change my code to make it return the results of all of the items in the select list? (I tested it and it is definitely picking up all the values in the select list).
    <b>
    DECLARE
    selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
    s   VARCHAR2(20);
    q varchar2(32767);
    BEGIN
    selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
    -- htp.p('COUNT: '||selected_items.count);
      FOR i in 1..selected_items.count LOOP
      s := TO_CHAR(selected_items(i));
    -- htp.p('First: '||s);
    -- htp.p('Second: '||:s);
    -- htp.p('Third: '||TO_CHAR(selected_items(i)));
      q:= 'SELECT  '||
    'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
    'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
    ' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
    'sum(orig_intrl) orig_intrl, '||
    'sum(orig_extrl) orig_extrl, '||
    'sum(recv_intrl) recv_intrl, '||
    'sum(recv_extrl) recv_extrl '||
    'FROM line_usage_sum_view '||
    'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
    --'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
    'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
    'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
    'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
    'AND '||
    :SORTFIELD||' BETWEEN '||
    'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
    'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
    -- htp.p('SQL query: '||q);
      RETURN q;
      END LOOP;
    END;</b>
    Thank you,
    Laura

    Laura,
    First, I would be careful of introducing SQL Injection possibilities. Any time I see
    'Select ... ' || :P123_FOO || ' ... '
    I worry about sql injection. In your case you are converting :P50_SELECTED_INSTRUMENTS into selected_items and then selected_items into s. So when I see
    'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
    I think, "I could use sql Injection and hack this."
    So, I would do some validation on :P50_SELECTED_INSTRUMENTS or some other method to avoid this.
    I'm not certain I understand your query. Do you really intend to allow the user to select the beginning of a string and then find all rows that start with that string? Or, do you just want to let them find when it matches the string. This is one way if you want to do matching:
    DECLARE
    selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
    s VARCHAR2(32767);
    q varchar2(32767);
    BEGIN
    -- Change the : separate string to be comma separated with quoted strings
    s := '''' || replace(:P50_SELECTED_INSTRUMENTS, ',', ''',''')|| '''' ;
    -- htp.p('COUNT: '||selected_items.count);
    q:= 'SELECT '||
    'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
    'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
    ' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
    'sum(orig_intrl) orig_intrl, '||
    'sum(orig_extrl) orig_extrl, '||
    'sum(recv_intrl) recv_intrl, '||
    'sum(recv_extrl) recv_extrl '||
    'FROM line_usage_sum_view '||
    'WHERE TO_CHAR(orig_geo_loc_sys) in (' || s ||' ) '||
    --'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
    'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
    'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
    'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
    'AND '||
    :SORTFIELD||' BETWEEN '||
    'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
    'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
    -- htp.p('SQL query: '||q);
    RETURN q;
    END;
    If you want to do something more like you originally stated, try this:
    DECLARE
    selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
    s VARCHAR2(20);
    q varchar2(32767);
    BEGIN
    selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
    -- htp.p('COUNT: '||selected_items.count);
    q:= 'SELECT '||
    'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
    'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
    ' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
    'sum(orig_intrl) orig_intrl, '||
    'sum(orig_extrl) orig_extrl, '||
    'sum(recv_intrl) recv_intrl, '||
    'sum(recv_extrl) recv_extrl '||
    'FROM line_usage_sum_view '||
    'WHERE 1=1 ';
    FOR i in 1..selected_items.count LOOP
    s := TO_CHAR(selected_items(i));
    q := q || ' and TO_CHAR(orig_geo_loc_sys) LIKE '''|| s ||'%'' ' ;
    END LOOP;
    q := q || ||'%'' '||
    --'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
    'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
    'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
    'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
    'AND '||
    :SORTFIELD||' BETWEEN '||
    'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
    'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
    -- htp.p('SQL query: '||q);
    RETURN q;
    END;
    Hope this helps...
    Anton

  • SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row

    I have a region with the following type:
    SQL Query (PL/SQL Function Body returning SQL query).
    In a search screen the users can enter different numbers, separated by an ENTER.
    I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
    It's something like this:
    If (:P30_POD Is Not Null) Then
    v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
    v_condition := ' AND ';
    End If;
    But the query doesn't return any rows.
    I tried to reproduce it in Toad:
    select * from asx_worklistitem
    where
    POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    ==> This is the query that does't return any rows
    select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    from dual;
    ==> This returns '541449200000171813','541449206006341366'
    select * from asx_worklistitem
    where pod in ('541449200000171813','541449206006341366');
    ==> and when I copy/paste this in the above query, it does return my rows.
    So why does my first query doesn't work?
    Doe anyone have any idea?
    Kind regards,
    Geert
    Message was edited by:
    Zorry

    Thanks for the help.
    I made it work, but via the following code:
    If (:P30_POD Is Not Null) Then
    v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
    v_where := v_where || v_condition || 'POD IN (';
    v_counter := 1;
    WHILE (v_counter < LENGTH(v_pods)) LOOP
    v_pod := SUBSTR(v_pods, v_counter, 18);
    IF (v_counter <> 1) THEN
    v_where := v_where || ',';
    END IF;
    v_where := v_where || '''' || v_pod || '''';
    v_counter := v_counter + 18;
    END LOOP;
    v_where := v_where || ')';
    v_condition := ' AND ';
    End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
    For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
    Because I think this will have a lot of overhead.
    I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible?

  • Using Package to produce pl/sql function body returning sql query Report

    I have existing code that we want to use in building reports in APEX. We are needing to modify it slightly to handle some new requirements, but would like to use them in reports based upon SQL query (pl/sql function body returning sql query) functionality.
    Any suggestions as how to call these in an APEX report region?
    Thank you,
    Tony Miller
    UTMB/EHN

    Hi Tony-
    I am also v new to Apex and you may have answered a question I was in search of. I, however, now have a couple more. First a bit of background-- Like in your situation, my college has a lot of existing code (400 +) that we need to get into Apex. The majority of this canned code contains one/both: 1) many lines, sometimes containing multiple select statements 2) imbedded create table & view statements (temp user owned). Up until reading your post, I was unable to figure out an easy way of getting this existing code into the product. Thanks. Now the questions, do you know how I would go about dealing with the create tables/views. I've read some posts on this forum which suggest temporary tables being unstable in this environment. Also, do you know if there's a size limitation when passing sql code via a function?
    As you may/may not be able to tell, I'm a bit lost right now... so any info you can provide would be appreciated. Thanks.
    Don

  • PL/SQL function body return sql query, no data found problem

    Hi all,
    we are trying to build a dynamic report based on item selection by user. we are using SQL Query (PL/SQL function body returning SQL query). However when a user change the item and submit the page . The following error appears.
    ORA-01403: no data found.
    our query is so simple
    declare
    l_query varchar2(30000) default 'select id from chw';
    begin
    if(:P11_PARA=1) then
    l_query:='select name from chw';
    end if;
    return l_query;
    end;
    any quick help please.

    Hello Mike,
    I tried it, the problem still exists.
    ORA-01403: no data found
    my new code is
    declare
    l_query varchar2(30000) default 'select id from chw';
    begin
    if (nvl(TO_NUMBER(:P11_PARA),0) = 1) then
    l_query:='select name from chw';
    end if;
    return (l_query);
    end;
    note, there is no process in this page.
    Edited by: M.Jabr on Oct 14, 2009 6:13 AM

  • PLSQL function body returning an sql report returns ORA-01403 No Data Found

    I am on APEX 3.1.2.00.02 and Oracle 10g.
    I am developing a report with SQL Query (PL/SQL function body returning SQL query) type. But on running the report I am getting
    report error:
    ORA-01403: no data found
    Region Source
    declare
      qry varchar2(32767);
    begin
      --Procedure call
      my_pkg.get_query(qry);
      htp.p(qry);
      return /*select 1 from dual */ qry;
    end;
    Procedure
    PROCEDURE get_query (V_QRY OUT VARCHAR2)
    IS
      qry varchar2(32767);
    begin
      qry := ' select name
         , max(decode(to_char(service_date,''Mon-YY''), ''Jan-09'', value, null)) as "Jan-09"
         , max(decode(to_char(service_date,''Mon-YY''), ''Jan-09'', value, null)) as "Feb-09"
         from MY_TABLE
         group by name ';
      V_QRY := qry;
    end;
    The query will be enhanced later to add more months and year based on user parameters once I am successfull in running report on this.
    I wish to use Query Specific Column names. I have seen this suggestion from Scott in a number of threads to use /*select 1 from dual */ with query but not working in my case.
    Can someone please suggest what can I do to make it working?
    Regards,
    Amir

    Firstly, have you unit tested the procedure (namely, within the SQL Workshop, SQL*Plus, SQL Developer,etc, etc.) to see if it produces the right output in the first place?
    If you have, and the query string generated is valid, try assigning the output to a page item (thus allowing you to view it in the session browser) or even pass the procedure output into the debug window (with the use of the wwv_flow.debug function). This might reveal some state or session change which is causing it not to return.You might find this easier to achieve if you change from a 'procedure and out parameter' combination to a 'function returning string' approach.
    Alternatively, try re-creating the report in a new region - occasionally I've come across weird bugs with report regions which resolved themselves in this manner.

  • PL/SQL function body returning SQL - report error:ORA-01403: no data found

    Hi,
    I am working on Application Express 4.0.2.00.06, and 11G database.
    I have a problem with classic report area of type - PL/SQL function body returning SQL query. Query works if I define region area as - Use Generic Column Names (parse query at runtime only), and does not when I define it - Use Query-Specific Column Names and Validate Query.
    I am getting error:
    report error:ORA-01403: no data found
    This is my query that is returned from function, and displayed with htp.p, and it works ok and returns data in SQL Developer and SQL Workshop (in Apex).
    <code>
    /* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA
    </code>
    As you can see, I even tried with workaround that I found on the previous post on the forum, and that is to put /* select 1 from dual */ to start query.
    Any help would be appriciated.

    /* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA

Maybe you are looking for

  • Scrolling to a given line or offset  in a JTextPane   *Please Help*

    I have looked on the web and do not see a solution to this problem. Maybee I am missing somthing very easy here. I am using a JTextPane to display text of multiple colours. The JTextPane is contained within a JScrollPane. I am using a highlighter to

  • Photo tags not working in Elements 11

    I upgaded to Eements 11 from 10 but now all the tagged photos will not come up when I hit the tag on the right on the Organize page.  I tried editing category of the tag from "imported" to "Other" but still no go unless I click on their file on the l

  • Problem in accessing a EJB bean through a servlet

    Dear all, I'm a trying to call a stateless session bean which has its home and component interfaces, which prints the name it receives from the servlet client. I'm trying to access a remote server EJB beans, which has been registered with JNDI & when

  • How to transport modified query from Dev to QA??

    Hi All, I have made a few changes to a query that has already been transported to QA from Dev. I have removed an Infoobject and introduced a new Infoobject and other such changes. Now I would like to transport the "new version" of the same query from

  • Passing parameter into report

    Hi, I am using RUN_REPORT_OBJECT to call my report from the menu. How do I pass parameters or values to my report? Is there another built-in function to do this? Please provide some sample codes. Thanks. null