Hibernate Oracle nested CURSOR

Hi All,
I'm connecting to an Oracle database, and accessing a function that returns a SYS_REFCURSOR. I can succesfully map the function using the following syntax:
@NamedNativeQuery( name = "blah_list"
, query = "{ call blah__function(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"
, resultClass = blah.class
, hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
, @QueryHint(name = "org.hibernate.readOnly", value = "true")
I can access the resultset it returns.
The issue is, within the resultset, there are nested CURSOR's.. ie:
SELECT my_column1, my_column2
,CURSOR (
SELECT my_column1
FROM my_table2
WHERE blah = blah ) column3
FROM my_table1
My question is, how do I loop through the resultset from the nested cursor? In the above, I can succesfully iterate through my_column1 and my_column2, but I can't through column3... Any ideas?!
Thanks very much! :)

What do you have so far?
Perhaps this will point you in the right direction.
    -- Return a ref cursor as an output parameter.
    CallableStatement cs = conn.prepareCall("begin open :c for select dummy, cursor(select dummy from dual) from dual; end;");
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.execute();
    -- Treat the output parameter as a result set.
    -- Column 1: String
    -- Column 2: Cursor (ResultSet)
    ResultSet rs = (ResultSet)cs.getObject(1);
    while(rs.next()) {
      String x = rs.getString(1);
      System.out.println("Column 1: " + x);
      -- Second column is a result set
      -- Column 1: String
      ResultSet c = (ResultSet)rs.getObject(2);
      while(c.next()) {
        String x2 = c.getString(1);
        System.out.println(" - Column 2: " + x2);
    cs.close();
Column 1: X
- Column 2: X

Similar Messages

  • Problem with generating xml and nested cursor (ora-600)

    I have a problem with generating xml (with dbms_xmlquery or xmlgen) and nested cursors.
    When I execute the following command, I get a ORA-600 error:
    select dbms_xmlquery.getxml('select mst_id
    , mst_source
    , cursor(select per.*
    , cursor(select ftm_fdf_number
    , ftm_value
    from t_feature_master
    where ftm_mstr_id = pers_master_id ) as features
    from t_person per
    where pers_master_id = mst_id ) as persons
    from f_master
    where mst_id = 3059435')
    from dual;
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00600: internal error code, arguments: [kokbnp2], [1731], [], [], [], [], [], []
    </ERROR>
    The problem is the second cursor (t_feature_master).
    I want to generate this:
    <master>
    <..>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    </master>
    If i execute the select-statement in sql-plus, then I get the next result.
    MST_ID MST_SOURCE PERSONS
    3059435 GG CURSOR STATEMENT : 3
    CURSOR STATEMENT : 3
    PERS_MASTER_ID PERS_TITLE PERS_INITI PERS_FIRSTNAME PERS_MIDDL PERS_LASTNAME
    3059435 W. Name
    CURSOR STATEMENT : 15
    FTM_FDF_NUMBER FTM_VALUE
    1 [email protected]
    10 ....
    I use Oracle 8.1.7.4 with Oracle XDK v9.2.0.5.0.
    Is this a bug and do somebody know a workaround?

    Very simple...Drop all type objects and nested tables and create them again. You will get no error. I'll explain the reason later.

  • Problem with XSU and DataSources with nested cursors?

    We are having a problem with the xsu libraries (OracleXMLQuery) using nested cursor syntax. The class returns nicely nested xml document when a database connection is established in the traditional/legacy manner of "class.forName(); DriverManager.registerDriver();" .
    However, when using a DataSouce object within a J2EE container, we get an xml document back that only represents the main level of the resultset with datatypes + memory addresses for the cursor fields (instead of the expected nested xml elements).
    Any thoughts?
    BTW, we are using the iPlanet Application Server with an Oracle 9i database.
    for instance:
    SELECT a, b, CURSOR(select m, n, o
    from table2
    where table1.x = table2.y),
    d, e, f
    FROM table1
    WHERE table1.name = 'Matt'

    Somebody please answer this question?

  • Stored Proc to create XML (using nested cursors)?

    From previous posts and from the
    documentation for XSQL I have
    discovered the joys of the
    CURSOR operator to create
    nested tables: i.e:
    SELECT dname,
    CURSOR (SELECT ename, sale....) as employees
    FROM dept
    However, I can not find any other
    documentation on how to program (PL/SQL)
    this functionality.
    I would like to use XSQL as
    it is exactly what I need, but
    I can not because my client does
    not want to use Java and they
    require IIS, but do not want to
    use JRUN, etc... (I tried this
    first).
    Since I only need to do an XML
    dump to a variable for processing
    by other parts of the program, life
    is fairly easy. I have already done
    this using Microsoft Data Shapes in
    VB (client does not want VC++ either...)
    However this was slow.
    In order to speed things up I want to
    create a stored procedure in Oracle to
    dump out the XML hierarchy to a variable given
    an SQLQuery input. If I use
    nested CURSORS this should be very easy.
    I would like to create a recursive PL/SQL
    function to handle this, but I have the
    following questions:
    1) I want the function to have an
    input of an open cursor,
    My plan is to detect the column
    type, when it is a nested cursor
    I would recurse with the open cursor
    to handle the nested cursor.
    2) I can not find a reference on to
    programatically handle "untyped collections
    based on an SQL statement" in anything
    other than the XSQL documentation.
    I am assuming that I can detect the
    column type of nested cursor somehow
    and then recurse on this to handle
    dump the recordset to an XML tagset.
    But I wuold like to find some documentation
    or examples on the calls, type statements,
    etc....

    I think the CURSOR() thing is an invention of the XSQL Servlet; not available elsewhere.
    You can accomplish nesting via user defined types and object views, using the "cast(multiset())" syntax, which is not documented particularly well either. This does require some setup, and so is not particularly dynamic.

  • Stored procedure: nested cursor problem

    Hey folks,
    i am really having a hard time trying to figure out how nested cursors work.
    What i want to do:
    -> Do one select statement and process the yielded rows with one cursor
    -> Do another select statement depending on the first cursor
    The code is quite simple, the beginning of the stored procedure is:
    create or replace
    PROCEDURE extractEntireMD IS
    CURSOR curTemplateUnitId IS
    SELECT
    tu.externalident,
    tu.templateunitid
    FROM
    templateunit tu
    WHERE
    tu.templateunitid = 100007;
    CURSOR curPartTypeId(templateUnitID IN varchar2) IS
    SELECT
    tpt.parttypeid
    FROM
    templateparttype tpt
    WHERE
    tpt.templateunitid = templateUnitID;
    From what i have read, this seems to be right.
    No i want to use this code like this:
    BEGIN
    FOR valInCurTemplateUnitId IN curTemplateUnitId LOOP
    DBMS_OUTPUT.PUT_LINE('ExtIdent: ' || valInCurTemplateUnitId.externalident);
    DBMS_OUTPUT.PUT_LINE('templateunitid: ' || valInCurTemplateUnitId.templateunitid);
    FOR valIncurPartTypeId IN curPartTypeId(valInCurTemplateUnitId.templateunitid) LOOP
    DBMS_OUTPUT.PUT_LINE('PartTypeId: ' || valIncurPartTypeId.parttypeid);
    END LOOP;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('No such data ');
    END;
    The problem:
    I seem to be doing something wrong, because Oracle does not heed the argument which i give to the second cursor from the first cursor:
    CURSOR curPartTypeId(templateUnitID IN varchar2) IS
    which i call via:
    FOR valIncurPartTypeId IN curPartTypeId(valInCurTemplateUnitId.templateunitid)
    Instead, oracle prints out __all__ templateunitids.
    If I modify the second cursor with a constant argument like this:
    CURSOR curPartTypeId(templateUnitID IN varchar2) IS
    SELECT DISTINCT
    tpt.parttypeid
    FROM
    templateparttype tpt
    WHERE
    tpt.templateunitid = 100007;
    The result is correct. So it seems like oracle simply disregards the parameter i am giving him for the second cursor.
    What am i doing wrong?

    > i am really having a hard time trying to figure out how nested cursors work.
    Good. I trust that this will result in the realisation that it is an idiotic thing to emulate the features of the SQL engine in PL/SQL. Only a fool thinks the he/she can outprogram and outsmart the SQL engine, and do things like nested loop joins better and faster in PL/SQL.
    Use SQL for the purpose it was designed. Use PL/SQL for the purpose it was designed.
    Joining of data? That is prime function and feature of SQL. Not PL/SQL.

  • Nested Cursors

    I'm trying to convert my look-up table data. But before I update the actual look-up tables themselves, I want to update the tables that "look" to the look-up tables. Hard to describe, but I posted on something similar to this before. I thought I had it worked out, but it's more complicated than I realized.
    I want to use a table I've created just for this called MATRIX_DEPT which houses the old and new dept. codes. Then my proc is supposed to look to the data dictionary table and update all the tables in the database that look to the DEPT table with the new dept. codes. I swear this ALMOST works!!
    Here's the code so far:
    CREATE OR REPLACE PROCEDURE CONVERSION IS
    CURSOR look_up IS
    SELECT TABLENAME, COLUMNNAME
    FROM DICTIONARY
    WHERE REFTABLE = 'DEPT';
    CURSOR matrix IS
    SELECT OLD_CODE, NEW_CODE
    FROM DEPT_MATRIX
    ORDER BY OLD_CODE;
    DDTBL VARCHAR2(30);
    DDCOL VARCHAR2(30);
    OLDCODE VARCHAR2(10);
    NEWCODE VARCHAR2(10);
    begin
    OPEN look_up;
    LOOP
    FETCH look_up INTO DDTBL, DDCOL;
    EXIT WHEN look_up%NOTFOUND;
    OPEN matrix;
    LOOP
    FETCH matrix INTO OLDCODE, NEWCODE;
    EXIT WHEN matrix%NOTFOUND;
    UPDATE DDTBL SET DDCOL = NEWCODE WHERE DDCOL = OLDCODE;
    END LOOP;
    CLOSE matrix;
    END LOOP;
    COMMIT;
    CLOSE look_up;
    END;
    Keep in mind - this ALMOST works!! The only part that's not working is the update statement. If I comment out the update statement and instead output the new and old codes, then the script appears to work exactly as coded.
    I looked into DBMS_SQL.PARSE() but couldn't get it work for this instance. All the examples I found on it were for just one cursor, not 2 nested cursors.
    Would it be better just to spool the update out and then run THAT script. Kind doesn't seem as slick though.

    How about using sql to create the update statements...
    SQL> CREATE TABLE t1 (dept VARCHAR2(10), c1 VARCHAR2(100));
    Table created.
    SQL> CREATE TABLE t2 (dept VARCHAR2(10), c2 VARCHAR2(100));
    Table created.
    SQL> CREATE TABLE t3 (dept VARCHAR2(10), c3 VARCHAR2(100));
    Table created.
    SQL> 
    SQL> CREATE TABLE dept_matrix(old_code VARCHAR2(10), new_code VARCHAR2(10));
    Table created.
    SQL> 
    SQL> INSERT INTO dept_matrix VALUES('o1','n1');
    1 row created.
    SQL> INSERT INTO dept_matrix VALUES('o2','n2');
    1 row created.
    SQL> INSERT INTO dept_matrix VALUES('o3','n3');
    1 row created.
    SQL> INSERT INTO dept_matrix VALUES('o4','n4');
    1 row created.
    SQL> 
    SQL> SELECT ''' when '''''||old_code||''''' then '''''||new_code||'''''''||-' FROM dept_matrix;
    '''WHEN'''''||OLD_CODE||'''''THEN'''''||NEW_C
    ' when ''o1'' then ''n1'''||-
    ' when ''o2'' then ''n2'''||-
    ' when ''o3'' then ''n3'''||-
    ' when ''o4'' then ''n4'''||-
    SQL> var mycase varchar2(1000);
    SQL> exec :mycase := ' set dept = case dept '||-
     ' when ''o1'' then ''n1'''||-
     ' when ''o2'' then ''n2'''||-
     ' when ''o3'' then ''n3'''||-
     ' when ''o4'' then ''n4'''||-
     ' end;';
    PL/SQL procedure successfully completed.
    SQL> SELECT 'update '||table_name||:mycase FROM user_tab_columns WHERE column_name = 'DEPT';
    'UPDATE'||TABLE_NAME||:MYCASE
    update T1 set dept = case dept  when 'o1' then 'n1' when 'o2' then 'n2' when 'o3' then 'n3' when 'o4'
    update T2 set dept = case dept  when 'o1' then 'n1' when 'o2' then 'n2' when 'o3' then 'n3' when 'o4'
    update T3 set dept = case dept  when 'o1' then 'n1' when 'o2' then 'n2' when 'o3' then 'n3' when 'o4'
    3 rows selected.
    SQL>

  • Xmlgen.getxml Nested Cursors with LONG RAW and BLOB Data Types

    I am trying to use a nested cursor with xmlgen.getxml that has a long raw or blob column. In either case, it will not return to me any data in the xml document pertaining to that LONG RAW or BLOB column. If I do not use a nested cursor, it works fine.
    Example:
    SELECT xmlgen.getxml('SELECT x, CURSOR(SELECT y FROM y_tab WHERE y_tab.x_id = x_tab.x_id) y FROM x_tab') FROM dual;
    This will not produce the information I am after.
    However, simply running:
    SELECT xmlgen.getxml('SELECT y FROM y_tab WHERE y_tab.x_id = <somevalue>') FROM dual;
    Works???
    Any ideas out there? Does anyone know if DBMS_XMLQUERY has this limitation?
    Thanks,
    Brad

    It doesn't appear that I am able to attach the PDF files.  Can you supply your email (or I can supply mine) so I can send you the three files:
    1.)  A good PDF (manually extracted from our old application)
    2.)  Dump of the same PDF file (includes header/footer info)
    3.)  A partially fixed PDF file (but some of the pictures / pages are cut off - specifically pages 3,5,9,10,12,14)
    The way that we have tried to fix the file (in example 3 above) is the following:
    a.)  Find the First Occurrence of "%PDF-"
    b.)  Find the Last Occurrence of "%%EOF"
    c.)  if the first "%PDF-" is found AND the last "%%EOF" is found, then
       i.)  Remove all data before the first %PDF-
       ii.)  Remove all data after the last %%EOF
    Let me know if you need any other information.
    Thanks,
    Mike

  • Hibernate: Oracle function call

    Hi,
    I want to call a oracle function through Hibernate.
    Can you please tell me steps how i can achieve the same.
    What ever i have read, i am mentioning below. Please let me if i am wrong
    1. Create a class TestFunction.java having getter setter methods
    2. Create TestFunction.hbm.xml which will be having following code
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>   
    <sql-query name="callFunction" callable="true">     
    <return class="TestFunction">               
    </return>     
    { call TestFunctionSQL(?,   :Name, :Age) } 
    </sql-query>
    </hibernate-mapping>I just copy pasted the code from some website and modified as per my need. Please let me know if anything is wrong above.
    3. I need to put the entry of TestFunction.hbm.xml in hibernate-cfg.xml
    4. I need to put the code in java to call teh stored proc. I dont have any idea how to do that.
    Please help
    ~Aman

    Before beginning : sorry if my answer isn't relevant but you asked no clear question
    I don't know a lot about it, even if all looks fine to me...
    the way to call a named query in hibernate is:
    List l =session.getNamedQuery("callFunction")
        .setString("param1", param1)
        .setString("param2, param2)
        .setMaxResults(50)
        .list(); // named parameters are betterSEE: http://www.hibernate.org/hib_docs/v3/reference/en/html/querysql.html
    specially $16.2 and $16.2.2
    //extract
    For Oracle the following rules apply:
    * A function must return a result set. The first parameter of a procedure must be an OUT that returns a result set. This is done by using a SYS_REFCURSOR type in Oracle 9 or 10. In Oracle you need to define a REF CURSOR type, see Oracle literature.

  • Java hibernate oracle sessions never get closed

    Hi all,
    I'm opening some Oracle sessions from a java-hibernate app. When a shutdown my java-hibernate the oracle sessions remain opened, even if the java process is not seen as running with "ps -fea | grep java".
    The problem is that this oracle sessions never die, they remain there and the only way to kill them is to either manually kill oracle process, or to restart the oracle instance or to restart the unix box where oracle resides.
    My java/hibernate app always close the session with a final statement in the source code, no matter what.
    Thanks in advanced.

    Hi all,
    I'm opening some Oracle sessions from a java-hibernate app. When a shutdown my java-hibernate the oracle sessions remain opened, even if the java process is not seen as running with "ps -fea | grep java".
    The problem is that this oracle sessions never die, they remain there and the only way to kill them is to either manually kill oracle process, or to restart the oracle instance or to restart the unix box where oracle resides.
    My java/hibernate app always close the session with a final statement in the source code, no matter what.
    Thanks in advanced.

  • Struts+hibernate+Oracle?

    ***log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).***
    ***log4j:WARN Please initialize the log4j system properly.***
    ***Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection***
    ***     at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)***
    ***     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)***
    ***     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)***
    ***     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)***
    ***     at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)***
    ***     at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)***
    ***     at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)***
    ***     at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)***
    ***     at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)***
    ***     at demo.dao.BookDAO.add(BookDAO.java:17)***
    ***     at demo.dao.BookDAO.main(BookDAO.java:101)***
    ***Caused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection***
    ***     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)***
    ***     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:161)***
    ***     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:273)***
    ***     at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:318)***
    ***     at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:343)***
    ***     at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:147)***
    ***     at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31)***
    ***     at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:545)***
    ***     at java.sql.DriverManager.getConnection(DriverManager.java:582)***
    ***     at java.sql.DriverManager.getConnection(DriverManager.java:154)***
    ***     at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.jav*a:110)**
    **     at org.hibernate.jdbc.ConnectionManager.o*penConnection(ConnectionManager.java:423)*
    *     ... 6 more*
    Edited by: Darryl Burke -- non-English text removed from subject line

    Hello,
    the language of these forums is English.
    We don't mind the non-English message within the Exception text itself, after all, you copy/paste them from your actual computer, but at least the title of the topic, and your question, should be spelled out in English.
    Oh, and I deliberately mentioned both a title and a plain-text question. I don't read your language, but I'm quite sure that the ~20 characters don't accurately describe yet your context, the problem you are trying to solve, and the attempts you have done already to solve it on your own.
    Best regards,
    Jérôme (a non-English contributor)
    Edited by: Darryl Burke -- non-English text removed from subject line

  • Strange problem: JDBC: Oracle Connection: Cursor hangs in ResultSet

    Hi,
    My program connects to an oracle db and queries all records (480'000) from a table with 4 columns (of which one, Z00_DATA, is of type LONG (and on average is about 1000 chars long)).
    From my Windows machine, the program runs fine.
    From a linux box the same program doesn't: it executes the statement, but when I skim through the returned resultset (even if I only count the number of records in it, it gets stuck on record 80. No exception thrown (I'm catching a general Exception object), it just hangs.
    [[ while (rs.next) { counter++; System.out.println(counter);} ]]
    When I change my query slightly and select only 3 columns (all except the LONG one), it runs fine again.
    This seems very odd to me since I'm not even reading the data inside the resultSet. (I will later, I'm just debugging now).
    Here's the code, if anyone can, please help.
    Charlie
    code:
    public void getNoticesData(String tableName, String[][] cols){   
    try {           
         // statements
         Statement stmt = alephConn.createStatement();
         String selectSQL = "select Z00_DOC_NUMBER, Z00_NO_LINES, Z00_DATA_LEN, Z00_DATA from lux01.z00";
         // get data from DB
         stmt.execute(selectSQL);
         ResultSet rs = stmt.getResultSet();
         p("SELECT SQL EXECUTED: " + selectSQL);
         int resultsCounter=0;
         // for all results
         while (rs.next()) {       
              resultsCounter++;
              p(resultsCounter + ", ");
         } // cursor
         // Close resources
         stmt.close();
    catch (Exception e) {     
         p("Exception thrown: " + e);
    finally {     
         p("Finally clause");
    }

    Hi,
    My program connects to an oracle db and queries all
    records (480'000) from a table with 4 columns (of
    which one, Z00_DATA, is of type LONG (and on average
    is about 1000 chars long)).
    And what is the maximum?
    And with the query order what is the size of the long field for the 80th row.
    From my Windows machine, the program runs fine.
    From a linux box the same program doesn't: it
    executes the statement, but when I skim through the
    returned resultset (even if I only count the number
    of records in it, it gets stuck on record 80. No
    exception thrown (I'm catching a general Exception
    object), it just hangs.Orcacle drivers for some reason have a tendency to have odd problems.
    What are the field types?
    Do you have the long field at the end of the field list?
    Try it with no data in the long field. And then increase it up to the maximum in the database.

  • Oracle Ref cursor- fetching

    Hi.. Greetings.
    I have a refcursor (aref_seq_reftyp) with 3 rows output. Like below
    Seq_order
    1
    2
    3
    I need to assign these 3 rows in 3 different variables while fetching the cursor. For ex.
    ls_seq_order1 :=1
    ls_seq_order2 :=2
    ls_seq_order3 :=3
    Please give me an idea to implement the above.

    This is the forum for Oracle's SQL Developer tool, not for general SQL and PL/SQL questions.
    Questions like this will get a better response in the PL/SQL forum.

  • How to write nested cursor for Adv. Collections dunning letter query

    I am trying to write a query for Advanced Collections duninng letters. Some accounts for this customer have invoices for more than one currency. In order to find all of the invoices this query works:
    select to_char(sysdate, 'MM/DD/YYYY') currsysdate,
    decode((per.person_first_name || per.person_last_name), null, ARPT_SQL_FUNC_UTIL.get_lookup_meaning('RESPONSIBILITY', 'APS'), per.person_first_name) first_name,
    per.person_last_name last_name,
    org.party_name org_name,
    loc.address1 address1,
    loc.address2 address2,
    loc.city city,
    loc.state state,
    loc.postal_code postal_code,
    per.person_first_name first_name1,
    (select sum(aps.amount_due_remaining)
    from
    iex_delinquencies_all dd,
    ar_payment_schedules_all aps
    where
    dd.payment_schedule_id = aps.payment_schedule_id and
    dd.party_cust_id = org.party_id and
    dd.cust_account_id = 255849 and
    dd.customer_site_use_id = 13071) total_amount_due_remaining,
    to_char(sysdate+7, 'MM/DD/YYYY') required_pay_date,
    rs.source_email collector_email,
    arc.alias collector_name,
    arc.telephone_number collector_phone,
    ar.account_number,
    cursor
    (select
    ct.trx_number invoice_number,
    to_char(ar.due_date, 'MM/DD/YYYY') due_date,
    ar.amount_due_remaining amount_due_remaining,
    ar.invoice_currency_code invoice_currency_code
    from
    iex_delinquencies_all d,
    ar_payment_schedules_all ar,
    ra_customer_trx_all ct
    where
    d.party_cust_id = org.party_id
    and d.cust_account_id = 255849
    and d.customer_site_use_id = 13071
    and d.payment_schedule_id = ar.payment_schedule_id
    and d.status = 'DELINQUENT'
    and ar.customer_trx_id = ct.customer_trx_id
    and ar.amount_due_remaining <> 0
    ) as payment_history
    from
    HZ_LOCATIONS loc
    ,hz_parties org
    ,hz_parties per
    ,jtf_rs_resource_extns rs
    ,ar_collectors arc
    ,hz_cust_accounts ar
    where
    loc.location_id = 11600
    and org.party_id= 255849
    --and per.party_id = nvl(:CONTACT_ID, org.party_id)
    and per.party_id = 255849
    and arc.resource_id = rs.resource_id
    and rs.RESOURCE_ID = 100022224
    and ar.cust_account_id = 182399
    But this assumes there is only one invoice currency but there isn't. Now I need to loop through all the distinct currencies in the ar_payment_schedules table so I was trying something like this:
    select to_char(sysdate, 'MM/DD/YYYY') currsysdate,
    decode((per.person_first_name || per.person_last_name), null, ARPT_SQL_FUNC_UTIL.get_lookup_meaning('RESPONSIBILITY', 'APS'), per.person_first_name) first_name,
    per.person_last_name last_name,
    org.party_name org_name,
    loc.address1 address1,
    loc.address2 address2,
    loc.city city,
    loc.state state,
    loc.postal_code postal_code,
    per.person_first_name first_name1,
    (select sum(aps.amount_due_remaining)
    from
    iex_delinquencies_all dd,
    ar_payment_schedules_all aps
    where
    dd.payment_schedule_id = aps.payment_schedule_id and
    dd.party_cust_id = org.party_id and
    dd.cust_account_id = 255849 and
    dd.customer_site_use_id = 13071) total_amount_due_remaining,
    to_char(sysdate+7, 'MM/DD/YYYY') required_pay_date,
    rs.source_email collector_email,
    arc.alias collector_name,
    arc.telephone_number collector_phone,
    ar.account_number,
    cursor
    (select distinct ar.invoice_currency_code invoice_currency_code
    from
    iex_delinquencies_all d,
    ar_payment_schedules_all ar,
    ra_customer_trx_all ct
    where
    d.party_cust_id = org.party_id
    and d.cust_account_id = 255849
    and d.customer_site_use_id = 13071
    and d.payment_schedule_id = ar.payment_schedule_id
    and d.status = 'DELINQUENT'
    and ar.customer_trx_id = ct.customer_trx_id
    and ar.amount_due_remaining <> 0
    cursor
    (select
    ct.trx_number invoice_number,
    to_char(ar.due_date, 'MM/DD/YYYY') due_date,
    ar.amount_due_remaining amount_due_remaining,
    --ar.invoice_currency_code invoice_currency_code
    from
    iex_delinquencies_all d,
    ar_payment_schedules_all ar,
    ra_customer_trx_all ct
    where
    d.party_cust_id = org.party_id
    and d.cust_account_id = 255849
    and d.customer_site_use_id = 13071
    and d.payment_schedule_id = ar.payment_schedule_id
    and d.status = 'DELINQUENT'
    and ar.customer_trx_id = ct.customer_trx_id
    and ar.amount_due_remaining <> 0
    and ar.invoice_currency_code = invoice_currency_code
    ) as payment_history
    ) as g_currency
    from
    HZ_LOCATIONS loc
    ,hz_parties org
    ,hz_parties per
    ,jtf_rs_resource_extns rs
    ,ar_collectors arc
    ,hz_cust_accounts ar
    where
    loc.location_id = 11600
    and org.party_id= 255849
    --and per.party_id = nvl(:CONTACT_ID, org.party_id)
    and per.party_id = 255849
    and arc.resource_id = rs.resource_id
    and rs.RESOURCE_ID = 100022224
    and ar.cust_account_id = 182399
    But I am getting missing right parenthesis error which leads me to think I am writing this correctly.

    Note the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*", so only for issues with the SQL Developer tool. Please post these questions under the dedicated SQL And PL/SQL forum (you've posted there before).
    Regards,
    K.

  • Oracle nested object table

    I've posted this question in sql/plsql forum but it may belong here.
    My question is how can i individually initialize/assign record to my nested table type wf_acts_t or wf_trans_t( either one or the other)?
    It maybe simply a case where I dont know how to accomplish this goal but I've got a workaround.
    CREATE TYPE wf_act_t IS OBJECT (
    a_NAME VARCHAR2 (100)
    CREATE TYPE wf_acts_t IS
    TABLE OF wf_act_t
    CREATE TYPE wf_tran_t IS OBJECT (
    wf_name VARCHAR2 (100)
    CREATE TYPE wf_trans_t IS
    TABLE OF wf_tran_t
    CREATE TYPE act_t IS OBJECT (
    act wf_acts_t,
    tran wf_trans_t
    create type bunch_of_act is table of act_t
    declare
    my_acts bunch_of_act := bunch_of_act();
    v_loop_count BINARY_INTEGER := 1;
    begin
    for wf_lkup_rec in(select * from wf_activities_lkup)
    loop
    my_acts.extend;
    /*here you cannot address wf_acts_t or wf_trans_t individually*/
    my_acts(v_loop_COUNT) :=
    act_t(
    wf_acts_t(wf_act_t(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null)
    wf_trans_t ( wf_tran_t (null))
    v_loop_count :=
    v_loop_count +1;
    end loop;
    v_loop_count := 1;
    dbms_output.put_line (my_acts (1).act(1).a_name);
    end;

    It can be something like that (I'm sorry for
    very silly example):
    SQL> declare 
      2     my_acts bunch_of_act := bunch_of_act(); 
      3     v_loop_count BINARY_INTEGER := 1; 
      4     ptr1 wf_acts_t; 
      5     ptr2 wf_trans_t; 
      6  begin     
      7 
      8    for wf_lkup_rec in(select e.* from emp e where rownum < 3) loop   
      9 
    10     /* Declare new table object*/
    11      ptr1 := wf_acts_t();
    12 
    13     /* Here we fill table individually */
    14     -- Add some loop:
    15 
    16      for k in 1..2 loop
    17       ptr1.extend;    
    18       ptr1(ptr1.last) := wf_act_t(wf_lkup_rec.ename);        
    19      end loop;
    20 
    21     /* Declare new table object*/    
    22      ptr2 := wf_trans_t();
    23 
    24     /* Here we fill table individually */    
    25     -- Add some loop
    26     for k in 1..2 loop
    27       ptr2.extend;
    28       ptr2(ptr2.last) := wf_tran_t(wf_lkup_rec.empno);    
    29     end loop;      
    30 
    31     my_acts.extend;
    32     my_acts(my_acts.last) :=  act_t(ptr1, ptr2);
    33 
    34    end loop;
    35 
    36    /* Individually take elements */
    37 
    38    for j in 1..my_acts.count loop
    39    
    40       dbms_output.put_line('Element ' || j || ' of top colletion contains '); 
    41 
    42       for k in 1..my_acts(j).act.count loop
    43           dbms_output.put_line(' act with name ' || my_acts(j).act(k).a_name); 
    44       end loop;
    45 
    46       dbms_output.put_line('and');
    47 
    48       for k in 1..my_acts(j).tran.count loop
    49           dbms_output.put_line(' tran with id ' || my_acts(j).tran(k).wf_name);
    50       end loop;
    51    
    52    end loop;
    53    
    54  end;
    55  /
    Element 1 of top colletion contains
    act with name SMITH
    act with name SMITH
    and
    tran with id 7369
    tran with id 7369
    Element 2 of top colletion contains
    act with name ALLEN
    act with name ALLEN
    and
    tran with id 7499
    tran with id 7499
    &nbsp
    PL/SQL procedure successfully completed.Rgds.

  • Help with building nested cursors

    Hello all,
    In one of our plsql procedures, we return a cursor of cursors that looks like this:
    OPEN main_cursor FOR
      SELECT
        CURSOR (
          SELECT query1
        ) c1,
        CURSOR (
          SELECT query2
        ) c2
      FROM DUAL;Now, we need to add a new condition that changes query1 into either query1a or query1b (depending of the condition). An easy refactor was done to the code as follows:
    IF (some_condition) THEN
      OPEN main_cursor FOR
        SELECT
          CURSOR (
            SELECT query1a
          ) c1,
          CURSOR (
            SELECT query2
          ) c2
        FROM DUAL;
    ELSE
      OPEN main_cursor FOR
        SELECT
          CURSOR (
            SELECT query1b
          ) c1,
          CURSOR (
            SELECT query2
          ) c2
        FROM DUAL;However, as you can see, query2 is duplicated in the if and else clauses. I wasn't able to find a way to avoid this duplication. Any ideas someone?
    Also, note that the difference between query1a and query1b is a table join.
    Thanks in advance,
    wf

    OPEN FOR allows for dynamic SQL where statements are put together by concatenating strings.
    http://www.morganslibrary.org/reference/ref_cursors.html
    Look at the demo of a Weakly Typed REF CURSOR.

Maybe you are looking for