How to read my cursor that is ref cursor returning user defined type

Hi
I have types defined as follows:
TYPE MY_RECORD IS RECORD (
COL1 TABLE1.COL1%TYPE,
COL2 TABLE1.COL2%TYPE
TYPE MY_CURSOR IS REF CURSOR
RETURN MY_RECORD;This is used as return type in a stored procedure.
I have a pl/sql block where I make a call to the SP that returns this cursor.
How can I read individual values being returned from SP?

SQL> create or replace package pkg
as
   type my_record is record (col1 emp.empno%type, col2 emp.ename%type);
   type my_cursor is ref cursor
      return my_record;
   procedure p (cur out my_cursor);
end pkg;
Package created.
SQL> create or replace package body pkg
as
   procedure p (cur out my_cursor)
   as
   begin
      open cur for
         select   empno, ename
           from   emp
          where   rownum <= 2;
   end p;
end pkg;
Package body created.
SQL> declare
   cur     pkg.my_cursor;
   e_rec   pkg.my_record;
begin
   pkg.p (cur);
   loop
      fetch cur into   e_rec;
      exit when cur%notfound;
      dbms_output.put ('Empno: ' || e_rec.col1);
      dbms_output.put_line ('; Ename: ' || e_rec.col2);
   end loop;
   close cur;
end;
Empno: 7369; Ename: SMITH
Empno: 7499; Ename: ALLEN
PL/SQL procedure successfully completed.

Similar Messages

  • How to print/store in file the ref cursor in pl/sql block ?

    How to print/store in file the ref cursor in pl/sql block ?.

    How to print/store in file the ref cursor in pl/sql block ?.You question is quite confusing?
    So, i'm providing link in this manner.
    For RefCursor,
    http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
    http://www.oracle.com/technology/oramag/code/tips2003/042003.html
    For UTL_FILE,
    http://www.morganslibrary.org/reference/utl_file.html
    Regards.
    Satyaki De.
    Updated with new morgan library link.
    Edited by: Satyaki_De on Feb 24, 2010 9:03 PM

  • HT4539 I have forgotten how to "read" a book that I downloaded.  Can anyone help?

    I have forgotten how to "read" a book that I downloaded.  Can anyone help?  Also, how would I download it to my documents for future reading or printing?  I am very new to this process.

    If it's an ibook that you've downloaded from iTunes then (if you don't already have it installed) you need to download the iBooks app to your iPad, iPhone or iPod Touch (an ibook can't be read on a Mac or PC), and you can then either (if you have the book on your computer) sync the book to your device via your computer's iTunes or re-download it directly in the iBooks app on the device (re-downloading).
    To sync a book to the iBooks app, connect your device to your computer and select it on the left-hand side of your computer's iTunes, and then use the Books tab on the right-hand side to select and sync the book to the iBooks app.
    There is a chapter on the iBooks app in the iPad, iPhone and iPod Touch's manual : http://support.apple.com/manuals/
    iBooks FAQ : http://support.apple.com/kb/HT4059

  • Ref cursor to another Ref cursor.

    Actually I have a ref cursor in a package x which has a procedure y.
    y has 4 parameters like procedure(a,b,c,d in out ref cursor type)
    I have another standalone procedure which has a ref cursor as out parameter and a,b,c as other parameters.
    This stand alone procedure implicitly calls the package procedure as x.y(a,b,c,d) d is a ref cursor defined in the stand alone procedure which is populated by the package's y procedure.
    My issue is that how to populate the standalone procedure's ref cursor with the value of the package's procedure's ref cursor with out using a temporary table?
    Please help me in this regard. It is urgent.

    Actually I have a ref cursor in a package x which has a procedure y.
    y has 4 parameters like procedure(a,b,c,d in out ref cursor type)
    I have another standalone procedure which has a ref cursor as out parameter and a,b,c as other parameters.
    This stand alone procedure implicitly calls the package procedure as x.y(a,b,c,d) d is a ref cursor defined in the stand alone procedure which is populated by the package's y procedure.
    My issue is that how to populate the standalone procedure's ref cursor with the value of the package's procedure's ref cursor with out using a temporary table?
    Please help me in this regard. It is urgent.

  • How to execute function takes user defined type parameters as input &output

    Hi All,
    I want to execute a function which takes user defined type as input & output parameters. But i don't know how to execute that function in pl/sql statements.
    CREATE TYPE T_INPUT AS OBJECT
    USER          VARCHAR2(255),
    APPLICATION     VARCHAR2(255),
    REFERENCE          VARCHAR2(30)
    ) NOT FINAL;
    CREATE TYPE T_ID UNDER T_INPUT
    E_ID                    VARCHAR2 (50),
    CODE                    VARCHAR2 (3),
    SERVICE                    VARCHAR2 (10),
    C_TYPE                    VARCHAR2 (1)
    ) NOT FINAL;
    CREATE TYPE T_OUTPUT AS OBJECT
         R_STATUS               NUMBER(10),
         E_DESC_LANG_1          VARCHAR2(1000),
         E_DESC_LANG_2          VARCHAR2(1000),
         A_REFERENCE          VARCHAR2(30)
    ) NOT FINAL;
    CREATE TYPE T_INFO UNDER T_OUTPUT
    E_INFO XMLTYPE
    CREATE FUNCTION Get_Dtls
    I_DETAILS IN T_ID,
    O_DETAILS OUT T_INFO
    RETURN NUMBER AS
    END;
    Here
    1. T_ID is an input parameter which is a combination of T_ID + T_INPUT,
    2. T_INFO is an output parameter which is a combination of T_INFO + T_OUTPUT.
    Here i'll assign the T_ID values.
    --- T_INPUT values
    USER          = "admin";
    APPLICATION     = "test";
    REFERENCE     = "null";
    ---- T_ID values
    E_ID               = "1234";
    CODE               = "TTT";
    SERVICE               = "NEW";
    C_TYPE = "P";
    Now i want to execute Get_Dtls function with T_ID,T_INFO parameters in pl/sql statements.
    I want to catch the E_INFO value from T_INFO type.
    How can i Do this ?
    Pls Help. Thanxs in advance.
    Anil.

    I am very new to this. New to Oracle, PL/SQL, OO programming or testing?
    set serveroutput on
    declare
      tst_obj ctype;
    begin
      tst_obj := pkg.proc(11);
      dbms_output.put_line('id='||tst_obj.id||'::code='||tst_obj.code||'::usage='||tst_obj.usage);
    end;
    /Generally I disapprove of the use of DBMS_OUTPUT (for just about anything) but it is sufficient to demonstrate the basic principle.
    Really you should start using proper testing practices, ideally with an automated test harness like QUTE.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • How to convert Collection to user defined type in db

    Hello All,
    I am using Apex 4.1.0.00.32 and Oracle 11g.
    I have page process to store the user selected rows (keys) in a collection as follows:
    declare
       temp varchar2(4000);
       vrow number;
       begin
       apex_collection.CREATE_OR_TRUNCATE_COLLECTION('SELECTED_PERSONS');
          IF (apex_application.g_f32.COUNT > 0) THEN
               FOR ii IN 1 .. htmldb_application.g_f32.COUNT
               LOOP
                    vrow := apex_application.g_f32(ii);
                   APEX_COLLECTION.ADD_MEMBER('SELECTED_PERSONS', apex_application.g_f30(vrow));
              END LOOP;
           END IF;
    end;I need to call a database function which takes an user defined type VC_ARRAY_1 defined as:
    create or replace TYPE  "VC_ARRAY_1"  AS TABLE OF VARCHAR2(4000) How do I convert the collection to VC_ARRAY_1, so that I can call the db function?
    Thanks,
    Rose

    Hi Joel,
    Yes, the collection contains the person_ids. But, I am selecting from a function which returns a pipelined table. In Oracle Database, few user defined types and functions are defined as given below:
    create or replace TYPE  "VC_ARRAY_1"   as table of varchar2(4000)
    create or replace FUNCTION   "GET_ARRAY" ( p_array  IN   varchar2,  p_delimiter   IN   varchar2  default ':')  return  VC_ARRAY_1 PIPELINED
    create or replace TYPE   "AFFECTED_INDIVIDUAL"  as object("PERSONKEY" VARCHAR2(4000),  "FIRST_NAME" VARCHAR2(4000), "LAST_NAME" VARCHAR2(4000)… more variables)
    create or replace TYPE  "AFF_IND_TAB"  as table of  "AFFECTED_INDIVIDUAL"
    create or replace FUNCTION  GET_AFF_INDIVIDUALS(personKeys IN VC_ARRAY_1) return  AFF_IND_TAB PIPELINEDThe function GET_AFF_INDIVIDUALS uses several tables and returns pipelined table. In Apex, I have a SQL query that feeds the Report query.
    select *  from table (get_aff_individuals(get_array(:F_SELECTED_PERSONS, ',')))The application item F_SELECTED_PERSONS is a varchar2 that contains comma separated person ids. I want to replace the application item with Apex collection. Initially, I thought that I can convert the apex collection to an array of vc_array_1.
    Thanks for your time and help.
    Rose

  • How to add a DataBase Field in PLD from a User Defined Table

    Hi All,
    Please tell me how should i add a database field in PLD from User Defined Field...
    The DropDown for tables in the Property window does not shows the User Define tables...How should i see them...
    Thanx in Advance
    Manish

    In PLD choose object Database. Then press Alt + table combobox, this will show the UDT. Then choose the column.

  • Object Diagrams that support user define type (create type....and subtypes

    Hello it would be very nice to be able to use user define types in a diagram, at this time oracle, ibm db2 9 and sql server 2005 suport sql ansi 2003 and to use all this potential we have to take tecnology foward. My sugestion is create object diagram that can help design all this funtionability, rational rose has the oracle8 addin this will give you an exact idea of what i am asking.
    Thanks for your atention and let me know if you are planing to do this.
    Perhaps this is not the right forum please tell me where I can send this as a future requests

    JDeveloper has a UML class diagram with transformation into a Java class diagram - are you looking for anything beyond that?

  • [Solved] 27.8.4 How to Create a VO on a REF CURSOR - Missing first row

    Searching the forum I found: BC4J - Get one less row from view object.
    Dive into BC4J related  --REF CURSOR (Resultset)
    The first message did not have any answers, and the second had a follow up question - still no answers though - and I thought I would try a different title.
    (This is off topic, but it would be a great help if the search results also displayed the number of replys in the thread. That way, I wouldn't have to view the messages that don't have responses.)
    (This will be deployed on a server that has the ADF for JDeveloper 10.1.2 installed, so using that version of JDeveloper to develop the app.)
    Okay, back to the problem ==>
    I created a VO from a ref cursor, using the manual as a guide. When I run a page that displays a read only table of the view object, I am missing the first row. (Always the first row!) I don't have any order set, and if I call the ref cursor in a Java program for testing, I see all rows and the count is correct.
    One other point, when I call the page, I get the following validation error:
    Validation Error
    You must correct the following error(s) before proceeding:
    * JBO-29000: Unexpected exception caught: java.lang.ClassCastException, msg=null
    * null
    I still see the table, it is just missing the first row of data.
    In my form I have first, previous set, next set , and last
    navigation buttons. If I press last then first, the error goes away. I still don't see the missing row though.
    Any guidance would be appreciated! I can post my code, but it is pretty much the same code in the AdvancedViewObjectExamples.zip in the ViewObjectOnRefCursor example. I just substituted my two package calls (getRefCursor and getRefCursorCount).
    Thanks, Ken

    Went back to a backup copy of the source. Fixed the error. Now I'm back to just not being able to see the first row of data.
    Additional Note: I had removed fields in the display. Once I truncated the ps_txn table in the schema defined by the model, the data would display (Still without the first record.)
    Are there any examples that are more in depth than the few pages in the developer guide?
    Here is the code for my VOImpl class:
    package newslinearchive.model.datamodel;
    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.sql.Types;
    import oracle.jbo.InvalidParamException;
    import oracle.jbo.JboException;
    import oracle.jbo.domain.Date;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jbo.server.QueryCollection;
    import oracle.jbo.server.SQLBuilder;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    // --- File generated by Oracle ADF Business Components Design Time.
    // --- Custom code may be added to this class.
    // --- Warning: Do not modify method signatures of generated methods.
    public class SearchRefCursorImpl extends ViewObjectImpl {
    * This is the default constructor (do not remove)
    public SearchRefCursorImpl() {
    * Overridden framework method.
    * Executed when the framework needs to issue the database query for
    * the query collection based on this view object. One view object
    * can produce many related result sets, each potentially the result
    * of different bind variable values. If the rowset in query is involved
    * in a framework-coordinated master/detail viewlink, then the params array
    * will contain one or more framework-supplied bind parameters. If there
    * are any user-supplied bind parameter values, they will PRECEED the
    * framework-supplied bind variable values in the params array, and the
    * number of user parameters will be indicated by the value of the
    * numUserParams argument.
    protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
    storeNewResultSet(qc,retrieveRefCursor(qc,params));
    super.executeQueryForCollection(qc, params, numUserParams);
    * Overridden framework method.
    * Wipe out all traces of a built-in query for this VO
    protected void create() {
    getViewDef().setQuery(null);
    getViewDef().setSelectClause(null);
    setQuery(null);
    * Overridden framework method.
    * The role of this method is to "fetch", populate, and return a single row
    * from the datasource by calling createNewRowForCollection() and populating
    * its attributes using populateAttributeForRow().
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
    * We ignore the JDBC ResultSet passed by the framework (null anyway) and
    * use the resultset that we've stored in the query-collection-private
    * user data storage
    rs = getResultSet(qc);
    * Create a new row to populate
    ViewRowImpl r = createNewRowForCollection(qc);
    try {
    * Populate new row by attribute slot number for current row in Result Set
    // populateAttributeForRow(r,0, rs.getLong(1));
    // populateAttributeForRow(r,1, rs.getString(2));
    // populateAttributeForRow(r,2, rs.getString(3));
    // MASTERID NOT NULL NUMBER
    populateAttributeForRow(r,0, rs.getBigDecimal(1));
    //ID NOT NULL NUMBER
    populateAttributeForRow(r,1, rs.getBigDecimal(2));
    // CAID NOT NULL NUMBER
    populateAttributeForRow(r,2, rs.getBigDecimal(3));
    // LANGUAGE NOT NULL VARCHAR2(30)
    populateAttributeForRow(r,3, rs.getString(4));
    // IS_CURRENT_VERSION NOT NULL NUMBER(1)
    populateAttributeForRow(r,4, rs.getBigDecimal(5));
    // FOLDER_ID NOT NULL NUMBER
    populateAttributeForRow(r,5, rs.getBigDecimal(6));
    // FOLDER_REGION_ID NOT NULL NUMBER
    populateAttributeForRow(r,6, rs.getBigDecimal(7));
    // NAME NOT NULL VARCHAR2(256)
    populateAttributeForRow(r,7, rs.getString(8));
    // DISPLAY_NAME VARCHAR2(256)
    populateAttributeForRow(r,8, rs.getString(9));
    // ITEMTYPE NOT NULL VARCHAR2(30)
    populateAttributeForRow(r,9, rs.getString(10));
    // SUBTYPE VARCHAR2(40)
    populateAttributeForRow(r,10, rs.getString(11));
    // SUBTYPE_CAID NUMBER
    populateAttributeForRow(r,11, rs.getBigDecimal(12));
    // PARENT_ITEM_ID NUMBER
    populateAttributeForRow(r,12, rs.getBigDecimal(13));
    // CATEGORY_ID NUMBER
    populateAttributeForRow(r,13, rs.getBigDecimal(14));
    // CATEGORY_CAID NUMBER
    populateAttributeForRow(r,14, rs.getBigDecimal(15));
    // AUTHOR VARCHAR2(50)
    populateAttributeForRow(r,15, rs.getString(16));
    // DESCRIPTION VARCHAR2(2000)
    populateAttributeForRow(r,16, rs.getString(17));
    // PUBLISH_DATE NOT NULL DATE
    populateAttributeForRow(r,17, rs.getDate(18));
    // EXPIREMODE VARCHAR2(90)
    populateAttributeForRow(r,18, rs.getString(19));
    // EXPIRENUMBER NUMBER
    populateAttributeForRow(r,19, rs.getBigDecimal(20));
    // EXPIREDATE DATE
    populateAttributeForRow(r,20, rs.getDate(21));
    // IMAGE VARCHAR2(350)
    populateAttributeForRow(r,21, rs.getString(22));
    // KEYWORDS VARCHAR2(2000)
    populateAttributeForRow(r,22, rs.getString(23));
    // URL VARCHAR2(4000)
    populateAttributeForRow(r,23, rs.getString(24));
    // FILENAME VARCHAR2(350)
    populateAttributeForRow(r,24, rs.getString(25));
    // TEXT CLOB()
    populateAttributeForRow(r,25, rs.getClob(26));
    // FOLDER_LINK_ID NUMBER
    populateAttributeForRow(r,26, rs.getBigDecimal(27));
    // FOLDER_LINK_CAID NUMBER
    populateAttributeForRow(r,27, rs.getBigDecimal(28));
    // ACTIVE NOT NULL NUMBER(1)
    populateAttributeForRow(r,28, rs.getBigDecimal(29));
    // CAN_BE_CHECKEDOUT NUMBER(1)
    populateAttributeForRow(r,29, rs.getBigDecimal(30));
    // IS_ITEM_CHECKEDOUT NUMBER(1)
    populateAttributeForRow(r,30, rs.getBigDecimal(31));
    // CHECKER_USERNAME VARCHAR2(256)
    populateAttributeForRow(r,31, rs.getString(32));
    // CHECKOUT_DATE DATE
    populateAttributeForRow(r,32, rs.getDate(33));
    // FULLSCREEN NOT NULL NUMBER(1)
    populateAttributeForRow(r,33, rs.getBigDecimal(34));
    // INPLACE NOT NULL NUMBER(1)
    populateAttributeForRow(r,34, rs.getBigDecimal(35));
    // CREATEDATE NOT NULL DATE
    populateAttributeForRow(r,35, rs.getDate(36));
    // CREATOR NOT NULL VARCHAR2(256)
    populateAttributeForRow(r,36, rs.getString(37));
    // UPDATEDATE DATE
    populateAttributeForRow(r,37, rs.getDate(38));
    // UPDATOR VARCHAR2(256)
    populateAttributeForRow(r,38, rs.getString(39));
    // SECURITY VARCHAR2(25)
    populateAttributeForRow(r,39, rs.getString(40));
    // VISIBLE NOT NULL NUMBER(1)
    populateAttributeForRow(r,40, rs.getBigDecimal(41));
    // SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,41, rs.getBigDecimal(42));
    // CATEGORY_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,42, rs.getBigDecimal(43));
    // AUTHOR_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,43, rs.getBigDecimal(44));
    // CREATE_DATE_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,44, rs.getBigDecimal(45));
    // ITEMTYPE_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,45, rs.getBigDecimal(46));
    catch (SQLException s) {
    throw new JboException(s);
    return r;
    * Overridden framework method.
    * Return true if the datasource has at least one more record to fetch.
    protected boolean hasNextForCollection(Object qc) {
    ResultSet rs = getResultSet(qc);
    boolean nextOne = false;
    try {
    nextOne = rs.next();
    * When were at the end of the result set, mark the query collection
    * as "FetchComplete".
    if (!nextOne) {
    setFetchCompleteForCollection(qc, true);
    * Close the result set, we're done with it
    rs.close();
    catch (SQLException s) {
    throw new JboException(s);
    return nextOne;
    * Overridden framework method.
    * The framework gives us a chance to clean up any resources related
    * to the datasource when a query collection is done being used.
    protected void releaseUserDataForCollection(Object qc, Object rs) {
    * Ignore the ResultSet passed in since we've created our own.
    * Fetch the ResultSet from the User-Data context instead
    ResultSet userDataRS = getResultSet(qc);
    if (userDataRS != null) {
    try {
    userDataRS.close();
    catch (SQLException s) {
    /* Ignore */
    super.releaseUserDataForCollection(qc, rs);
    * Overridden framework method
    * Return the number of rows that would be returned by executing
    * the query implied by the datasource. This gives the developer a
    * chance to perform a fast count of the rows that would be retrieved
    * if all rows were fetched from the database. In the default implementation
    * the framework will perform a SELECT COUNT(*) FROM (...) wrapper query
    * to let the database return the count. This count might only be an estimate
    * depending on how resource-intensive it would be to actually count the rows.
    public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
    Long result = (Long)callStoredFunction(NUMBER,
    "PORTAL.SEARCH_REFCURSOR.getRefCursorCount",
    viewRowSet.getParameters(true));
    return result.longValue();
    // ------------- PRIVATE METHODS ----------------
    * Return a JDBC ResultSet representing the REF CURSOR return
    * value from our stored package function.
    * new Object[]{getNamedBindParamValue("Email",params)}
    private ResultSet retrieveRefCursor(Object qc, Object[] params) {
    ResultSet rs = (ResultSet)callStoredFunction(OracleTypes.CURSOR,
    "PORTAL.SEARCH_REFCURSOR.getRefCursor",
    null);
    return rs ;
    private Object getNamedBindParamValue(String varName, Object[] params) {
    Object result = null;
    if (getBindingStyle() == SQLBuilder.BINDING_STYLE_ORACLE_NAME) {
    if (params != null) {
    for (Object param : params) {
    Object[] nameValue = (Object[])param;
    String name = (String)nameValue[0];
    if (name.equals(varName)) {
    return (String)nameValue[1];
    throw new JboException("No bind variable named '"+varName+"'");
    * Store a new result set in the query-collection-private user-data context
    private void storeNewResultSet(Object qc, ResultSet rs) {
    ResultSet existingRs = getResultSet(qc);
    // If this query collection is getting reused, close out any previous rowset
    if (existingRs != null) {
    try {existingRs.close();} catch (SQLException s) {}
    setUserDataForCollection(qc,rs);
    hasNextForCollection(qc); // Prime the pump with the first row.
    * Retrieve the result set wrapper from the query-collection user-data
    private ResultSet getResultSet(Object qc) {
    return (ResultSet)getUserDataForCollection(qc);
    * Return either null or a new oracle.jbo.domain.Date
    private static Date nullOrNewDate(Timestamp t) {
    return t != null ? new Date(t) : null;
    * Return either null or a new oracle.jbo.domain.Number
    private static Number nullOrNewNumber(BigDecimal b) {
    try {
    return b != null ? new Number(b) : null;
    catch (SQLException s) { }
    return null;
    //----------------[ Begin Helper Code ]------------------------------
    public static int NUMBER = Types.NUMERIC;
    public static int DATE = Types.DATE;
    public static int VARCHAR2 = Types.VARCHAR;
    public static int CLOB = Types.CLOB;
    * Simplifies calling a stored function with bind variables
    * You can use the NUMBER, DATE, and VARCHAR2 constants in this
    * class to indicate the function return type for these three common types,
    * otherwise use one of the JDBC types in the java.sql.Types class.
    * NOTE: If you want to invoke a stored procedure without any bind variables
    * ==== then you can just use the basic getDBTransaction().executeCommand()
    * @param sqlReturnType JDBC datatype constant of function return value
    * @param stmt stored function statement
    * @param bindVars Object array of parameters
    * @return function return value as an Object
    protected Object callStoredFunction(int sqlReturnType, String stmt,
    Object[] bindVars) {
    CallableStatement st = null;
    try {
    st = getDBTransaction().createCallableStatement("begin ? := " + stmt +
    "; end;", 0);
    st.registerOutParameter(1, sqlReturnType);
    if (bindVars != null) {
    for (int z = 0; z < bindVars.length; z++) {
    st.setObject(z + 2, bindVars[z]);
    st.executeUpdate();
    return st.getObject(1);
    catch (SQLException e) {
    throw new JboException(e);
    finally {
    if (st != null) {
    try {
    st.close();
    catch (SQLException e) {}
    /**Gets the bind variable value for Email
    public String getEmail() {
    return (String)getNamedWhereClauseParam("Email");
    /**Sets <code>value</code> for bind variable Email
    public void setEmail(String value) {
    setNamedWhereClauseParam("Email", value);
    /**getEstimatedRowCount - overridden for custom java data source support.
    public long getEstimatedRowCount() {
    long value = super.getEstimatedRowCount();
    return value;
    Thanks, Ken

  • How to put a collection into a Ref Cursor?

    Hi,
    I am trying to create a procedure (inside a package) which fills a collection and I need to fill a ref cursor (out parameter) with this collection. I can fill the collection but I how can I fill the ref cursor? I am receiving the message "PL/SQL: ORA-00902: invalid datatype" (Highlighted below as comments)
    I have a limitation: I am not allowed to create any kind of objects at the database schema level, so I have to create them inside the package. I'm writting it with SQL Tools 1.4, I'm also not allowed to do this in SQL+.
    This is the code of the package. The cursors' selects were simplified just because they are not the problem, but their structure is like follows below.
    CREATE OR REPLACE PACKAGE U3.PKG_TESTE AS
    TYPE REC_TYPE IS RECORD(
    COL1 VARCHAR2(50) ,
    COL2 VARCHAR2(100) ,
    COL3 VARCHAR2(20) ,
    COL4 VARCHAR2(30) ,
    COL5 VARCHAR2(100) ,
    COL6 VARCHAR2(50) ,
    COL7 NUMBER(3) ,
    COL8 VARCHAR2(30) ,
    COL9 VARCHAR2(16) ,
    COL10 VARCHAR2(50) ,
    COL11 NUMBER(4) ,
    COL12 VARCHAR2(40)
    TYPE REC_TYPE_LIST IS TABLE OF REC_TYPE
    INDEX BY BINARY_INTEGER;
    TYPE C_RESULTSET IS REF CURSOR;
    VAR_TAB_TESTE     REC_TYPE_LIST;
    PROCEDURE     Z_REC_INSTANCE
    pUSER_SYS_CODE VARCHAR2,
    pSYS_SEG_CODE VARCHAR2,
    pComplFiltro VARCHAR2,
    pCodInter NUMBER,
    cResultset out C_RESULTSET
    END PKG_TESTE ;
    CREATE OR REPLACE PACKAGE BODY U3.PKG_TESTE
    AS
    PROCEDURE Z_REC_INSTANCE
    pUSER_SYS_CODE varchar2,
    pSYS_SEG_CODE varchar2,
    pComplFiltro varchar2,
    pCodInter number
    AS
    cursor cur1 is
    select 'A' COL1, 'B' COL2, 'C' COL3, 'D' COL4, 'E' COL5,
    'F' COL6, 'G' COL7, 'H' COL8
    FROM DUAL;
    regCur1 cur1%rowtype;
    cursor cur2 is
    SELECT 'I' C1, 'J' C2, 'K' C3, 'L' C4
    FROM DUAL;
    regCur2 cur2%rowtype;
    varSQL varchar2(4000);
    varCOL10s varchar2(100);
    varFiltroAtrib varchar2(100);
    varCount number(10);
    BEGIN
    varCount := 1;
    open cur1;
    Loop
    fetch cur1 into regCur1;
    exit when cur1%notfound;
    open cur2;
    Loop
    fetch cur2 into regCur2;
    exit when cur2%notfound;
    VAR_TAB_TESTE(varCount).COL1 := regCur1.COL1;
    VAR_TAB_TESTE(varCount).COL2 := regCur1.COL2;
    VAR_TAB_TESTE(varCount).COL3 := regCur1.COL3;
    VAR_TAB_TESTE(varCount).COL4 := regCur1.COL4;
    VAR_TAB_TESTE(varCount).COL5 := regCur1.COL5;
    VAR_TAB_TESTE(varCount).COL6 := regCur1.COL6;
    VAR_TAB_TESTE(varCount).COL7 := regCur1.COL7;
    VAR_TAB_TESTE(varCount).COL8 := regCur1.COL8;
    VAR_TAB_TESTE(varCount).COL9 := regCur2.C1;
    VAR_TAB_TESTE(varCount).COL10 := regCur2.C2;
    VAR_TAB_TESTE(varCount).COL11 := regCur2.C3;
    VAR_TAB_TESTE(varCount).COL12 := regCur2.C4;
    varCount := varCount + 1;
    end Loop;
    end Loop;
    -- I'd like to do something like this:
    -- c_resultset := select * from var_tab_teste;
    -- but i don't know how to put the records of the type on the ref cursor,
    -- probably because I don't know how to select them
    -- pl/sql: ora-00902: invalid datatype
    for varCount in (select COL1 from table( CAST ( VAR_TAB_TESTE AS REC_TYPE_LIST ) ))
    loop
    dbms_output.put('WORKS');
    end loop;
    END Z_REC_INSTANCE;
    END PKG_TESTE;
    SHOW     ERR     PACKAGE          PKG_TESTE;
    SHOW     ERR     PACKAGE BODY     PKG_TESTE;
    SHOW     ERR     PROCEDURE     PKG_TESTE.Z_REC_INSTANCE;
    I'm using:
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    Thanks in advance.

    I don't have the exact version but in 9iOK I lied, I found a 9i instance ;-)
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
    JServer Release 9.2.0.7.0 - Production
    SQL> CREATE TABLE table_name (column_name VARCHAR2 (30));
    Table created.
    SQL> INSERT INTO table_name VALUES ('value one');
    1 row created.
    SQL> INSERT INTO table_name VALUES ('value two');
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3     TYPE collection_type_name IS TABLE OF table_name%ROWTYPE;
      4
      5     FUNCTION function_name
      6        RETURN collection_type_name PIPELINED;
      7  END package_name;
      8  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3     FUNCTION function_name
      4        RETURN collection_type_name PIPELINED
      5     IS
      6     BEGIN
      7        FOR record_name IN (SELECT column_name
      8                            FROM   table_name) LOOP
      9           PIPE ROW (record_name);
    10        END LOOP;
    11
    12        RETURN;
    13     END function_name;
    14  END package_name;
    15  /
    Package body created.
    SQL> VARIABLE variable_name REFCURSOR;
    SQL> BEGIN
      2     OPEN :variable_name FOR
      3        SELECT column_name
      4        FROM   TABLE (package_name.function_name);
      5  END;
      6  /
    PL/SQL procedure successfully completed.
    SQL> PRINT variable_name;
    COLUMN_NAME
    value one
    value two
    SQL>I recommend though that you test this thoroughly. There were bugs with this approach when it was newly introduced that prevented you from dropping the package.

  • Call procedure that uses REF CURSOR?

    Can someone tell me how to call a procedure that uses a REF CURSOR?
    Procedure is something like this:
    PROCEDURE my_proc
    P_PROG_ID IN VARCHAR2,
    P_CRITERIA IN VARCHAR2,
    P_TASKCURSOR OUT MYREFCUR
    IS
    blah, blah blah
    I tried this to call the procedure:
    exec my_proc(variable1,variable2,variable3)
    but I don't know how to define variable3.
    Can someone help me out?

    Based on the parameters for the procedure, it looks like you have a cursor (myrefcursor) defined in a package somewhere. So, in sqlplus, you would need to do it in an anonymous block, something like:
    DECLARE
       l_cur package_name,myrefcur;
       variables to hold cursor fields
    BEGIN
       my_proc('ID', 'Criteria', l_cur);
       LOOP
          FETCH l_cur INTO variables to hold cursor fields
          EXIT WHEN l_cur%NOTFOUND;
          Do something with variables
       END LOOP;
       CLOSE l_cur;
    END;If you are on Oracle 9 or higher, assuming that myrefcursor is weakly typed,
    you could change the definition of the procedure to:
    PROCEDURE my_proc (p_prog_id    IN  VARCHAR2,
                       p_criteria   IN  VARCHAR2,
                       P_TASKCURSOR OUT SYS_REFCURSOR)then you could call it in sql plus like:
    -- Define the variables
    var var1 VARCHAR2(100);
    var var2 VARCHAR2(100);
    var cur  SYS_REFCURSOR;
    -- Assign Vlaues to the IN parameters
    EXEC :var1 := 'ID'; :var2 := 'Criteria';
    EXEC my_proc(:var1, :var2, :cur);
    -- See the contents of the cursor
    print curHTH
    John

  • How to read .dat files that are hidden?

    Is it possible to read .dat files that are set to hidden? 'cause what i did was i created a .dat file and set its attributes to hidden and my Read file code cannot read hidden files.
    here's my Read file code:
    Scanner read=new Scanner(FileReader("C:\password.dat"));
    and another thing, how do you Write a .dat file that is hidden too? 'cause my password.dat file needs to be updated.
    here's my Write file code:
    PrintWriter write=new PrintWriter("C:\password.dat");
    thank for the help.

    There should not be any problems opening up hidden files. Your problem is probably elsewhere (for example, you didn't escape the backslash, so what you posted is not your code).

  • How to pass list of values to REF CURSOR?

    Hi there,
    I have a package for ref cursor return as following:
    <pre>
    create or replace package p_mypkg as
    type t_ref_cur is REF CURSOR;
    function f_t_refcur (strsql varchar2) return t_ref_cur;
    end;
    create or replace package body p_mypkg as
    function f_t_refcur(strsql varchar2) return t_ref_cur as
         cur t_ref_cur;
    sql_stmt varchar2(1000);
         begin
    sql_stmt:='select object_name,object_type from user_objects where object_type in (:j)';
              open cur for sql_stmt using strsql;
              return cur;
         end;
    end;
    var results refcursor
    begin
    :results:=p_mypkg.f_t_refcur('TABLE');
    end;
    print results
    var results refcursor
    begin
    :results:=p_mypkg.f_t_refcur('INDEX');
    end;
    print results
    I got the result sets using just one value.
    But I got nothing when use two values as input.
    Any idea?
    var results refcursor
    begin
    :results:=p_mypkg.f_t_refcur('''TABLE'',''INDEX''');
    end;
    print results
    SQL>
    no rows selected
    Thanks,
    SZ

    You can also use ...from table(... :
    create or replace type numbertype
    as object
    (nr number(20,10) )
    create or replace type number_table
    as table of numbertype
    create or replace procedure tableselect
    ( p_numbers in number_table
    , p_ref_result out sys_refcursor)
    is
    begin
      open p_ref_result for
        select *
        from employees , (select /*+ cardinality(tab 10) */ tab.nr from table(p_numbers) tab) tbnrs
        where id = tbnrs.nr;
    end;
    /

  • How to read the messeges that appear as number!

    Hi,
    can nay one hear tell me how to read the messege if u have the messege number?
    i tried with Tcode SE91, but there it is allowing only three characteristics where my messege number has 4, ( exmaple G003 )
    Thanks,
    Ravi

    Ravi,
    LOOP AT MESSTAB.
          MOVE-CORRESPONDING MESSTAB TO MESSAGES.
          MESSAGES-PLNUM = PLAN-PLNUM.
          CALL FUNCTION 'FORMAT_MESSAGE'
               EXPORTING
                    ID   = MESSTAB-MSGID
                    LANG = MESSTAB-MSGSPRA
                    NO   = MESSTAB-MSGNR
                    V1   = MESSTAB-MSGV1
                    V2   = MESSTAB-MSGV2
                    V3   = MESSTAB-MSGV3
                    V4   = MESSTAB-MSGV4
               IMPORTING
                    MSG  = MESSAGES-TEXT.
          APPEND MESSAGES.
        ENDLOOP.
    Don't forget to reward if useful...

  • Is there a different way to open a cursor for a ref cursor procedure?

    hello everybody
    i have two cursors, cur_a and cur_b, declared somewhere else in my application.
    These two cursors have the same fields, in the same order, and i have to treat both in the same way. So i wrote a routine that gets as input a ref cursor based on the cur_a rowtype, and i am trying to use this routine for both.
    The problem is that i am not able to open outside the routine the cursor in a different way than usual...
    the common method is :
    declare curs ref cursor ...
    begin
    open curs for (select *...)
    end;
    instead i would like to obtain something different
    declare curs ref cursor ...
    begin
    open curs for cur_a
    end;

    hi
    thanks for answering
    i wanted just to give a better idea, anyway you were near to get it.
    the only difference is that the two cursors are not written in dynamic sql, just like strings, but are real cursors.
    anyway, this is the version of the package i need, but i am not able to compile
    (your original code is commented and immediately below there is my code)
    CREATE OR REPLACE PACKAGE BODY mytest
    IS
    --cur_a VARCHAR2(200) := 'SELECT dummy FROM DUAL';
    CURSOR cur_a
    IS
    SELECT dummy
    FROM DUAL;
    --cur_b VARCHAR2(200) := 'SELECT ''fred'' FROM DUAL';
    CURSOR cur_b
    IS
    SELECT 'fred' fred
    FROM DUAL;
    TYPE t_cur_a IS REF CURSOR
    RETURN cur_a%ROWTYPE
    --PROCEDURE routine_a_b (p_cur SYS_REFCURSOR) IS
    PROCEDURE routine_a_b (p_cur t_cur_a)
    IS
    v_x VARCHAR2 (10);
    BEGIN
    LOOP
    FETCH p_cur
    INTO v_x;
    EXIT WHEN p_cur%NOTFOUND;
    DBMS_OUTPUT.put_line (v_x);
    END LOOP;
    END;
    PROCEDURE doit
    IS
    --v_curs SYS_REFCURSOR;
    v_curs t_cur_a;
    BEGIN
    NULL;
    -- open v_curs FOR cur_a;
    OPEN v_curs FOR cur_a;
    routine_a_b (v_curs);
    CLOSE v_curs;
    -- open v_curs FOR cur_b;
    -- routine_a_b(v_curs);
    -- close v_curs;
    END;
    END;
    the error is:
    cursor 'V_CURS' cannot be used in dynamic SQL OPEN statement
    i did read that if use weak ref cursor, it could work, so i declare the ref cursor type in this way:
    TYPE t_cur_a IS REF CURSOR;
    instead than
    TYPE t_cur_a IS REF CURSOR
    RETURN cur_a%ROWTYPE
    what i get is another error (in the open cursor command)
    PLS-00382: expression is of wrong type....
    but if i replace
    OPEN v_curs FOR cur_a;
    with
    OPEN v_curs for select dummy from dual;
    it works... but i already knew it.. :-)
    anyway, i used a work around to resolve it, so it's just philosophy

Maybe you are looking for

  • Dynamic insertion of data in a Dynamic Column in a table

    Hi EveryBody , I have a table where i am increasing the column dynamically . I need to insert data through PreparedStatement Like pst = con.prepareStatement(CBBsqlConstants.addOrderItem);                pst.setString(1,ein);                pst.setStr

  • Database snapshot

    Hi, I have setup a basic replication i.e. materialized replication or snapshot replication. I am using oracle 9i database servers. The following is my setup: site A - master site used for production database site B - DR site I have to replicate selec

  • Dynamic Programming: Adding Transparent Container to Root Element

    Hi, I simply am adding a Transparent Container to the Root Element dynamically and I am getting the error "The ASSERT condition was violated". Does anyone have an idea what the problem is. Below is my VERY MUCH simplified code: method WDDOMODIFYVIEW

  • How do I connect different secttions of a song together?

    How do I connect different secttions of a song together?

  • Labview with arduino

    Hi I'm beginner learn LabVIEW, I need  help about my program for final project. I try to make spirometer using sensor MPX2010dp, differential ammplifier AD620, and Arduino Uno.  But when I try to show th result from my hardware to LabVIEW the graphyc