Sort problem on dynamic query !!

Hi,
I have a dynamic query written in pl/sql, when I check "Sort" for each field in Report Attribute, error message raised up as "ORA-01785: ORDER BY item must be the number of a SELECT-list expression".
If I do not check Sort, it works fine. In my apps I need all fields sorted by user, how to fix this problem?
My query as below:
declare
query varchar2(2000):='select';
s_class varchar2(1000);
cursor c1 is select * from demo_preference;
begin
for c1_val in c1 loop
if c1_val.login is not null then
query := query ||' ' || 'login' || ',';
end if;
if c1_val.id is not null then
query := query ||' ' || 'id' || ',';
end if;
end loop;
query := SUBSTR(query, 1, length(query)-1);
s_class := '(NVL(:P2_class, ''%'' || ''null%'') = ''%'' || ''null%'' OR
EXISTS (SELECT 1 FROM apex_collections WHERE collection_name = ''P2CLASSCOL'' AND c001 = class))';
query := query ||' ' || 'from ming.reg_report_view1 where'
|| ' ' || s_class;
return(query);
end;

Maybe the internally mapped column used when you clicked on sort is not shown in the report. Try using aliases when you construct the query string, it could help apex internally in identifying a column even if its order changes for a different user. After all the column order in the code is dynamic and I guess even the no of columns displayed might vary both of which could make sorting on a column identified with a number, invalid.
How about displaying the report query somewhere, so that you know what is the exact query being processed, it might give you better information about the problem.
If the problem persists, then use a collection that is fetched those record using the same query string and change the report to refer the collection and then set column sorting on. This way apex would get confused on what columns are being sorted and it would just sort on a c001..c050 column as though it was a string(yes problems with number columns sorting when you do this).

Similar Messages

  • Create table problem using Dynamic Query

    Hi all,
    I want to create a temporary table within a stored procedure so I decided to do it using a dynamic query:
    create or replace procedure p1
    as
    begin
    execute immediate 'CREATE GLOBAL TEMPORARY TABLE tt(id number(2))';
    end;
    / It created successfuly but when I execute that procedure I got:SQL> exec p1;
    BEGIN p1; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "SCOTT.P1", line 4
    ORA-06512: at line 1 While I can create that table using the same user without any problem!
    My question is:What privilege should I grant to user(minimum of privileges please! ) to execute that procedure successfuly?
    -Thanks

    Hi,
    To say a little bit more about Nicolas' answer:
    SQL> grant create table to scott;
    This is the right answer, but you might wonder why you have to do so if you usually can create tables with this user..
    11:59:19 TEST.SQL>CREATE USER UTEST
    11:59:28   2  IDENTIFIED BY UTEST;
    User created.
    11:59:35 TEST.SQL>CREATE ROLE RTEST;
    Role created.
    11:59:40 TEST.SQL>GRANT RTEST TO UTEST;
    Grant succeeded.
    11:59:45 TEST.SQL>GRANT CREATE SESSION TO RTEST;
    Grant succeeded.
    11:59:54 TEST.SQL>GRANT CREATE TABLE TO RTEST;
    Grant succeeded.
    12:00:03 TEST.SQL>GRANT UNLIMITED TABLESPACE TO UTEST;
    Grant succeeded.
    12:00:17 TEST.SQL>CREATE PROCEDURE UTEST.CT_TEST
    12:00:32   2  IS
    12:00:33   3  BEGIN
    12:00:35   4  EXECUTE IMMEDIATE 'CREATE TABLE UTEST.TTEST (A NUMBER)';
    12:00:56   5  END;
    12:00:58   6  /
    Procedure created.
    12:00:59 TEST.SQL>EXEC UTEST.CT_TEST;
    BEGIN UTEST.CT_TEST; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "UTEST.CT_TEST", line 4
    ORA-06512: at line 1
    12:01:06 TEST.SQL>GRANT CREATE TABLE TO UTEST;
    Grant succeeded.
    12:01:15 TEST.SQL>EXEC UTEST.CT_TEST;
    PL/SQL procedure successfully completed.Don't forget that when you're using PL/SQL, privileges granted via roles are ignored!
    Regards,
    Yoann.

  • Problem on Dynamic Query Report

    Hello,
    I need to perform a report depend on the user who is accesing to my application,
    I am using the following query:
    declare
    q varchar2(4000);
    v_usuario varchar2(10);
    begin
    SET v_usuario = (CASE
    WHEN :P101_USERNAME='janet' THEN v_usuario = 'JA'
    WHEN :P101_USERNAME='cesar' THEN v_usuario = 'CC'
    WHEN :P101_USERNAME='luisjavier' THEN v_usuario = 'LT'
    WHEN :P101_USERNAME='mauricio' THEN v_usuario = 'MO'
    WHEN :P101_USERNAME='enrique' THEN v_usuario = 'EH'
    ELSE ' ')
    q:=' select p.cliente, ';
    q:=q||' p.partner, ';
    q:=q||' p.channel_mgr, ';
    q:=q||' p.fm_sales_rep, ';
    q:=q||' p.status, ';
    q:=q||' p.sc_leader, ';
    q:=q||' p.sector, ';
    q:=q||' p.fecha_inicio, ';
    q:=q||' from adminorv.proyectosongoing p ';
    q:=q||' where p.sc_leader = v_usuario';
    return q;
    end;
    However, I got this error:1 error has occurred
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-06550: line 1, column 9: PLS-00103: Encountered the symbol "" when expecting one of the following: begin function package pragma procedure subtype type use form current cursor
    Somebody can give a hint?

    You have a bunch of syntax errors there.
    The code should look more like this:
    declare
    q varchar2(4000);
    v_usuario varchar2(10);
    begin
    v_usuario := (CASE
    WHEN :P101_USERNAME='janet' THEN  'JA'
    WHEN :P101_USERNAME='cesar' THEN  'CC'
    WHEN :P101_USERNAME='luisjavier' THEN  'LT'
    WHEN :P101_USERNAME='mauricio' THEN  'MO'
    WHEN :P101_USERNAME='enrique' THEN  'EH'
    ELSE ' ' END);
    q:=' select p.cliente, ';
    q:=q||' p.partner, ';
    q:=q||' p.channel_mgr, ';
    q:=q||' p.fm_sales_rep, ';
    q:=q||' p.status, ';
    q:=q||' p.sc_leader, ';
    q:=q||' p.sector, ';
    q:=q||' p.fecha_inicio ';
    q:=q||' from adminorv.proyectosongoing p ';
    q:=q||' where p.sc_leader = v_usuario';
    return q;
    end;But I don't see why you are using dynamic SQL and a function returning a query here.
    That could be done with just a simple query like this:
    select p.cliente, p.partner, p.channel_mgr, p.fm_sales_rep, p.status, p.sc_leader,
           p.sector, p.fecha_inicio
      from adminorv.proyectosongoing p
    where p.sc_leader = CASE WHEN :P101_USERNAME = 'janet' THEN 'JA'
                              WHEN :P101_USERNAME = 'cesar' THEN 'CC'
                              WHEN :P101_USERNAME = 'luisjavier' THEN 'LT'
                              WHEN :P101_USERNAME = 'mauricio' THEN 'MO'
                              WHEN :P101_USERNAME = 'enrique' THEN 'EH'
                              ELSE ' '
                          END

  • Sorting problem in BW query

    Dear All,
    Two of my columns in the query are 'Emp no.' and 'Seq. no.' Since 'Emp no' is at the first column, I am able to sort it.
    But for each 'Emp no', there are 5 'Seq nos'. Now for each 'Emp no', I need to sort the 'Seq nos'. also.
    How will I do that ? Please advise.
    <removed by moderator>
    Thanks,
    Srinivas
    Edited by: Siegfried Szameitat on Nov 7, 2008 9:52 AM

    Hi Vishal,
    I agree with you. Placing 'Seq no' in the first column will not solve my issue rather it will add up more.
    Is there any other technique or manipulations you can think of ?
    Thanks,
    Srinivas

  • Problem with dynamic query in Forms Builder

    Hi,
    I need in forms builder cursor in procedure which parameter is a whole query. But i stuck when i wanna give some text in signs '' to procedure.
    I wanna give like test('select ' ||'test' || ' from dual');
    But this is not good beacuse it is missing ''.
    Query which procedure get is select test from dual.
    The right sql would be select 'test' from dual.
    How could i pass signs '' to procedure.
    Any ideas.
    Thanks in advance.

    test('select ''' ||'test' || ''' from dual');Francois

  • 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

  • Error in dynamic query while sort allowed is true

    Dear all
    I m entering search creteria dynamically and search result comes in a table.I have set Sort allowed true for all colum in that table.So when I click on any colum for sorting and then search data, an order by clause will be added before dynamic section of the code.
    and query becomes as -
    SELECT pp.name,
    pp.segment1 project_number,
    pp.project_status_code,
    pps.project_status_name,
    pp.carrying_out_organization_id,
    hau.name organization,
    pp.project_type,
    pp.project_id,
    pp.start_date,
    pp.completion_date
    FROM pa_projects pp,
    pa_project_statuses pps,
    hr_all_organization_units_v hau
    WHERE pp.project_status_code = pps.project_status_code AND
    pp.carrying_out_organization_id = hau.organization_id AND
    pp.template_flag <> 'Y') QRSLT ORDER BY PROJECT_NUMBER asc AND pps.project_status_name ='Active'
    as u can see at the last line of code ' ORDER BY PROJECT_NUMBER asc ' is added before qynamic section 'AND pps.project_status_name ='Active' and it makes query invalid.
    If u have any suggestions ,Plz let me know.
    Thanks
    bhupendra

    Bhupendra,
    As per Oracle SQL Standard "Order by clause" always be the last synatx of Query.
    As per OAF Standard , always avoid for dynamic query, instead we can create View Object.
    As you are created dynamic query with "order by clause" syntax., The code is also adding where clause after the order by clause. So you are getting the error.
    So Delete the "order by clause", it will work fine.
    After adding the where clause (i.e. AND pps.project_status_name ='Active' ), You should add the setOrderByClause();
    Thanks,
    Kumar

  • 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]

  • 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 Querying in ESB

    Hey,
    I am trying to implement dynamic querying using the query by example concept. My requirement is as follows:
    "Say I have 5 inputs , I need to fetch rows from the database using those 5 inputs as a part of my where clause"
    The user input are optional. Hence using the query by example concept I was able to filter rows.
    But the problem is as follows:
    1) I have a "time from" and "a time to" field as user inputs. I need to filter the fetched rows so that time is in that time range only. I do not know how to implement this also along with the above concept as there is no place for a where clause.
    Any help/suggestions would be appreciated.
    Thanks

    I tried applying the patch, but it gives the following error:
    OPatch detects your platform as 207 while this patch 6133448 supports platforms:
    0 (Generic Platform)
    This patch is not suitable for this operating system.
    Please contact support for the correct patch.
    ERROR: OPatch failed during pre-reqs check.
    OPatch returns with error code = 150
    I downloaded for the OS I am on, but always the generic patch downloads; i guess this generic one should work for all platforms. Opatch version is 1.0.0.0.56.

  • Unable to retrieve results using dynamic query

    Hi Experts,
    I have created a custom table and have created a custom bol to integrate it with web ui. I have redefined the dynamic query result method of genil layer. I find the data into LT_RESULT but when I invoke the root list method the LR_OBJECT does not contain the values.
    Please see below the code that I have written.
    ====================================
    METHOD IF_GENIL_APPL_INTLAY~GET_DYNAMIC_QUERY_RESULT.
    DATA: LR_OBJECT TYPE REF TO IF_GENIL_CONT_ROOT_OBJECT,
    LT_RESULT TYPE TABLE OF ZCRMST_XXXX,
    LV_DYN_WHERE TYPE STRING,
    LV_LEN TYPE I,
    LS_RANGE TYPE SELOPTOBJ.
    DATA: LT_XXXX TYPE TABLE OF SELOPTOBJ,
    LT_YYYY TYPE TABLE OF SELOPTOBJ.
    FIELD-SYMBOLS: <LFS_RESULT> TYPE ZCRMST_XXXX,
    <LFS_SELECTION_RANGE> TYPE GENILT_SELECTION_PARAMETER.
    decomposition of selection parameters and build a dynamic where condition
    SELECT * FROM ZXXXX INTO TABLE LT_RESULT[].
    CHECK LINES( LT_RESULT[] ) > 0.
    LOOP AT LT_RESULT[] ASSIGNING <LFS_RESULT>.
    LR_OBJECT = IV_ROOT_LIST->ADD_OBJECT( IV_OBJECT_NAME = 'Root'
    IS_OBJECT_KEY = <LFS_RESULT>-XXXX ).
    CHECK LR_OBJECT IS BOUND.
    LR_OBJECT->SET_QUERY_ROOT( ABAP_TRUE ).
    ENDLOOP.
    ENDMETHOD.
    ==================================================
    Thanks in advance,

    Hi,
    Please check your get_objects method of the genil class. I made some changes to my implementation of get_objects method and it fixed the problem.
    Regards,
    Sandeep

  • How to use dynamic query for this ??

    hi , i am new to ABAP. i got a requirement to write  dynamic query for the following code.
    kindly address. two set of queries are same.but condition is different.
    .IF p_psd EQ ' '.
    *C--End of change DF 1232137- (Transport # :CIDK980530 )
    *C--FETCH THE Deliverd Quantiity and Material Number
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng IN s_dqt
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
        IF sy-subrc = 0.
          SORT t_afpo BY aufnr matnr pwerk.
    *C--FETCH THE OBJECT NUMBER
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_aufk BY aufnr objnr.
    *C--FETCH THE Target Quantiity
            SELECT aufnr "ORDER number
                   gamng "Total order quantity target quantity
                   FROM afko
                   INTO TABLE t_afko
                   FOR ALL ENTRIES IN t_afpo
                   WHERE aufnr = t_afpo-aufnr
                   AND   gamng IN s_tqt.
            IF sy-subrc = 0.
              SORT t_afko BY aufnr .
            ENDIF.
          ENDIF.
        ELSE.
          MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
          LEAVE LIST-PROCESSING.
        ENDIF.
    *C--Begin of change DF 1232137- (Transport # :CIDK980530 )
      ENDIF.
      IF p_psd EQ c_x.
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng > 0
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
    if sy-subrc = 0.
    *C--FETCH THE OBJECT NUMBER
        IF  NOT t_afpo[] IS INITIAL.
          SORT t_afpo BY aufnr matnr pwerk.
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
        IF NOT t_afpo[] IS INITIAL.
    *C--FETCH THE Target Quantiity
          SELECT aufnr "ORDER number
                 gamng "Total order quantity target quantity
                 FROM afko
                 INTO TABLE t_afko
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr
                 AND   gamng <> t_afpo-wemng .
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
      ELSE.
        MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
        LEAVE LIST-PROCESSING.
      ENDIF.
    Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tags

    Hi friend,
    Try using MACRO and dynamic WHERE condition.
    Group simialr Select statements under a Macro.
    Build a dynamic where by checking conditions
    Call macro passing dynamic where condition.
    TABLES afpo.
    DATA: str TYPE string.
    *Macro definition
    DEFINE operation.
      select single *
           from afpo into afpo
           where (&1).    " Dynamic condition
    END-OF-DEFINITION.
    *Build dynamic WHERE by checking some conditions
    *If conditon 
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
    *Else
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
    *Endif.
    *Call Macro passing dynamic WHERE condition
    operation str.

  • How to create custom BOL object for dynamic query in CRM 7.0

    Hi,
    Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
    Regards,
    Kamesh Bathla
    Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PM

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

  • Help! Inaccessible iterator when using dynamic query

    Hi!
    I have a problem retreiving results from a dynamic query into sqlj iterator.
    I consulted the Oracle App Dev Guide and Oracle SQLJ Dev Guide and wrote the following code:
    <PRE>
    package pmServer;
    #sql iterator LocIterator (int id, String name);
    public class pmRISDImpl
    public int GetLocations(...)
    LocIterator locIt;
    String q = "select ID, NAME from PMADM.LOCATIONS";
    #sql
    BEGIN
    open :OUT locIt for :q;
    END;
    </PRE>
    When I try to compile it using tools provided by JDeveloper ver 3.2.2.(Build 915) for JDK 1.2.2 I get error for #sql statement:
    Inaccessible Java type for host item locIt (at position #1): pmServer.LocIterator
    and warning:
    Type pmServer.LocIterator of host item locIt (at position #1) is not permitted in JDBC. This will not be portable.
    Althow the code is identcal to those demonstrated in Oracle document "Oracle8 i
    SQLJ Developers Guide and Reference
    Release 3 (8.1.7)
    July 2000
    Part No. A83723-01" pp 12-67 (PL/SQL in SQLJ for Dynamic SQLDynamicDemo.sqlj). There it looks like
    <PRE>
    private static void dynamicSelectMany(String what_cond)
    throws SQLException {
    System.out.println("dynamic multi-row query on table emp");
    Employees empIter;
    // table/column names cannot be bind args in dynamic PL/SQL, so
    // build up query as Java string
    String query = "select ename, sal from emp " +
    (((what_cond == null) &#0124; &#0124; (what_cond.equals(""))) ? "" :
    (" where " + what_cond)) +
    "order by ename";
    #sql {
    begin
    open :OUT empIter for -- opening ref cursor with dynamic query
    :query;
    -- can have USING clause here if needed
    end;
    while (empIter.next()) {
    System.out.println("Employee " + empIter.ename() +
    " has salary " + empIter.sal() );
    empIter.close();
    </PRE>
    Please guide me what should I do to get it working.
    null

    In the CAST statement the SQLJ runtime must be able to produce an instance of you SQLJ iterator using Java reflection.
    This necessitates that the iterator class must be accessible by public.
    You have two options:
    (1) Declare the iterator public. This requires that you put it in its own file LocIterator.sqlj:
    #sql public iterator LocIterator (int id, String name);
    (2) Declare the iterator as an inner class. In this case you want to make it public static (that is it does not require an instance of the outer class in scope). You might write the following.
    package pmServer;
    public class pmRISDImpl
    #sql public static iterator LocIterator (int id, String name);
    (3) If you are using Oracle 9i you have another option. You can embed dynamic SQL fragments directly in your SQLJ code and do not need to use the CAST:
    public int GetLocations(...)
    LocIterator locIt;
    String q = "PMADM.LOCATIONS";
    #sql locIt = { select ID, NAME from :{q} }; // Note new syntax :{q} for embedding SQL source code
    }

  • Executing a dynamic query in CLOB

    We are storing the sql query in a CLOB object(as the query can grow very big)
    we want to open a cursor based on the query stored in the CLOB object, we have used the following statement
    OPEN cur_get_result FOR TO_CHAR(l_sql_query);
    FETCH cur_get_result BULK COLLECT INTO l_get_result;
    CLOSE cur_get_result;
    to get the result set from the query in to a collection object.
    we are getting the error as
    ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 5156, maximum: 4000)
    please give us your inputs to solve the above problem.

    > The query will go beyond 32K in size. We are getting
    this error when the query reaches beyond 32K. Is
    there anyway to handle this situation?
    Yes. You borrow my lead pipe and beat the <insert word here> out of the person(s) who decided that designing and coding and implementing a 32+ KB dynamic SQL is the right thing to do.
    I have dealt with some pretty large and complex SQLs through the years. But over 32KB worth of DYNAMIC SQL!? That is a maintenance nightmare. How on earth can that be debugged for runtime errors? Or tuned for performance?
    Something are... well, just plain silly IMO. And a 32+ KB dynamic SQL statement is one of them.
    > Any kind of help would be appreciated.
    I would rethink this approach - kneejerk reaction that this must be a design flaw. Even if not, I would implement this as a mix of SQL and PL/SQL code to modularise it, in order to get a handle on performance and debugging and maintenance issues.
    Er.. sorry if I'm a bit blunt here, but heck.. a 32+ KB dynamic SQL is a prime candidate for a Guinness Book of Records award and a top spot in oracle-wtf.blogspot.com. :-)

Maybe you are looking for