Ref cursors vs Custom Types

I am looking for an advice on performance.
We have a .NET 4.0 web service sitting on top of Oracle 10G database. So far we have been using REF CURSORS and it worked well for us. But, there is this one place in the service where we expose an "overview" type which requires a number of "single-record" datapoints from a lot of tables. If we go with our old approach, we'd get 14 REF CURSORS for 1 WS call. Each of these REF CURSORS is super fast because it retrieves jus a single record, but still it's 14 of those. All datapoints come from different tables.
Would you recommend that I switch to OUTPUT parameters that use Oracle UDT types that map into .NET types instead of using REF CURSORS? For multi-record data points, I think it's REF CURSORS, but for single-record datapoints, I just can't decide.
I ran a load test against a single-record REF CURSOR vs Oracle UDT, and performance is virtually the same.
What would you suggest I do? Is there another, more performant, way?
Thanks.
Evgueni

Hi Eric,
I'm new here, so not sure how much help I can be... but I think that part of your question can be answered on page 3-37 through to 3-39 of the Oracle .Net Data Provider manual (data conversions).
Here's the best I can do so far on nullable columns, using a datareader:
if (reader["Type_Id"] as DBNull == null)
ct.TypeId = Convert.ToInt32(reader["Type_Id"]);
My column in this case was defined on the DB as int - which IIRC really gets translated to NUMBER(38,0)... which is way too large for an int32. Never mind, I am going to sort that out in the DB sometime soon... but in the meantime, the Convert.ToInt32 (or should I have used int32.Parse or similar???) does the trick. I think if my ct.TypeId had been declared as 'decimal', or if my db column had been defined as NUMBER(5,0) (and kept ct.TypeId as Int) then either change would have meant I could get away without the conversion... but don't quote me on that ;)
Nij

Similar Messages

  • Iteration problem in ref cursor

    hi all
    declare
    type ref_cur is ref cursor;
    p_ref_cur ref_cur;
    type namelist is table of varchar2(10);
    type address is table of varchar2(20);
    p_namelist namelist;
    p_address address;
    begin
    open p_ref_cur for 'select emp_code,EMP_ADDR from emp_det_bak';
    fetch p_ref_cur bulk collect into p_namelist,p_address;
    for i in p_ref_cur
    loop
    dbms_output.put_line('this is for testing '||p_ref_cur(i));
    end loop;
    end;
    i found error like following--
    ERROR at line 11:
    ORA-06550: line 11, column 10:
    PLS-00221: 'P_REF_CUR' is not a procedure or is undefined
    ORA-06550: line 11, column 1:
    PL/SQL: Statement ignored
    if i use
    for i in p_ref_cur.first..p_ref_cur.last
    i got error message like --
    Invalid reference to variable 'P_REF_CUR'
    can anyone pls tell me what wrong i'm doing and if i want to iterate through will i use
    like--while(p_ref_cur.next) loop
    please suggest me.
    Message was edited by:
    p.bhaskar

    > please suggest me.
    Well, there is a fairly easy way to create a refcursor with the ability to loop through the columns of the cursor - without knowing what the columns are.
    However, this is not always an ideal approach. It uses VARCHAR2 as the data type for all columns and requires the source SQL to to construct a collection.
    Here's a brief example of this approach:
    SQL> create or replace type TColumns as table of varchar2(4000);
    2 /
    Type created.
    SQL>
    SQL> create or replace procedure DisplaySQL( sqlStatement varchar2 ) is
    2 c SYS_REFCURSOR;
    3 colList TColumns;
    4 rowCnt integer := 0;
    5 begin
    6 open c for sqlStatement;
    7
    8 loop
    9 fetch c into colList;
    10 exit when c%NOTFOUND;
    11
    12 rowCnt := rowCnt + 1;
    13
    14 W( '****************' ); -- W = DBMS_OUTPUT.put_line
    15 W( 'row: '||rowCnt );
    16 W( 'columns: '||colList.Count );
    17
    18 for i in 1..colList.Count
    19 loop
    20 W( 'column='||i||' value='||colList(i) );
    21 end loop;
    22 end loop;
    23
    24 W( '****************' );
    25 close c;
    26 end;
    27 /
    Procedure created.
    SQL>
    SQL>
    SQL> var SQL varchar2(4000);
    SQL>
    SQL> exec :SQL := 'select TColumns(created, object_type, object_name) from ALL_OBJECTS where rownum = 1';
    PL/SQL procedure successfully completed.
    SQL> exec DisplaySQL( :SQL )
    row: 1
    columns: 3
    column=1 value=2005/07/21 19:04:20
    column=2 value=TABLE
    column=3 value=CON$
    PL/SQL procedure successfully completed.
    SQL>
    SQL> exec :SQL := 'select TColumns(created, object_type, object_name) from
    ALL_OBJECTS where rownum = 1 UNION ALL select TColumns(dummy,SYSDATE) from
    DUAL';
    PL/SQL procedure successfully completed.
    SQL> exec DisplaySQL( :SQL )
    row: 1
    columns: 3
    column=1 value=2005/07/21 19:04:20
    column=2 value=TABLE
    column=3 value=CON$
    row: 2
    columns: 2
    column=1 value=X
    column=2 value=2007/05/16 13:14:56
    PL/SQL procedure successfully completed.
    SQL>

  • 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

  • Returning a Ref cursor as an OUT Parameter

    Hi Guys
    I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
    TYPE type_dept_Rec IS RECORD(deptNo varchar2);
    TYPE type_prod_Rec IS RECORD(prodType varchar2);
    TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
    TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
    PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptType, productCursor OUT deptType) IS
    BEGIN
    OPEN deptCursor FOR SELECT
    deptNo
    from
    DEPT
    where
    pinCode = pinCode;
    OPEN productCursor FOR SELECT
    prodCode
    from
    PROD
    where
    prodType = prodType;
    end;

    A Correction to the above code snippet
    Hi Guys
    I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
    TYPE type_dept_Rec IS RECORD(deptNo varchar2);
    TYPE type_prod_Rec IS RECORD(prodType varchar2);
    TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
    TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
    PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptCursor, productCursor OUT prodCursor) IS
    BEGIN
    OPEN deptCursor FOR SELECT
    deptNo
    from
    DEPT
    where
    pinCode = pinCode;
    OPEN productCursor FOR SELECT
    prodCode
    from
    PROD
    where
    prodType = prodType;
    end

  • Will REF CURSOR support for Oracle Forms 6i?

    Hi,
    I need to use ref cursor in my from. My cursor query should be dynamically append the "where clause". Hence I used the dynamic query with ref cursor.
    But my problem is , when I compile the form it gives error for the line " OPEN emp_record FOR l_query;"
    You need to use "select" statement.
    Is there any solution for this in forms?
    I know it supports for other PL/SQL areas.
    Please help me. below is my code sample,
      DECLARE
    TYPE emp_refcur IS REF CURSOR;
    emp_record    emp_refcur;
    TYPE rec_emp_data IS RECORD
        emp_no              VARCHAR2(40),
      emp_rec             rec_emp_data;
      l_query               VARCHAR2(4000);
    BEGIN
         l_query := 'SELECT empno
                     FROM emp ';
          IF :CONTROL.ename IS NOT NULL THEN     
              l_query := l_query||' AND ename = '''||:CONTROL.ename||''' ';           
          END IF;
         OPEN emp_record FOR l_query;
         LOOP
            FETCH emp_record INTO emp_rec;
            EXIT WHEN emp_record%NOTFOUND;
           dbms_output.put_line(emp_rec.emp_no);
        END LOOP;
        CLOSE emp_record;     
    END;      Thanks
    Rajesh

    Hi,
    It's been a while since I used Forms 6i, but I remember hitting a similar problem. I don't think (and stress think!) that the PLSQL engine that comes with Forms 6i recognises ref_cursors.
    The work-around I used was to move the functionality to the database and call it from forms.
    Hope this helps.
    Regards
    Ian

  • Using plsql table and ref cursor in oracle forms 10g

    Hi all,
    Can anyone give me an example of a scenario where we need to create a form manually based on a database stored procedures.
    And in that procedure i have created a pl/sql table and a ref cursor in data base level.
    CREATE OR REPLACE PACKAGE SCOTT.BONUS_PKG IS TYPE bonus_rec
    IS RECORD(
    empno     bonus_EMP.empno%TYPE,
    ename     bonus_EMP.ename%TYPE,
    job     bonus_EMP.job%TYPE,
    sal     bonus_EMP.sal%TYPE,
    comm     bonus_EMP.comm%TYPE);
    TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
    TYPE bontab IS TABLE OF bonus_rec INDEX BY BINARY_INTEGER;
    PROCEDURE bonus_refcur(bonus_data IN OUT b_cursor);
    PROCEDURE bonus_query(bonus_data IN OUT bontab);
    END bonus_pkg;
    CREATE OR REPLACE PACKAGE BODY SCOTT.BONUS_PKG IS
    PROCEDURE bonus_query(bonus_data IN OUT bontab) IS
    ii NUMBER;
    CURSOR bonselect IS
    SELECT empno, ename, job, sal, comm FROM bonus_EMP ORDER BY empno;
    BEGIN
    OPEN bonselect;
    ii := 1;
    LOOP
    FETCH bonselect INTO
    bonus_data( ii ).empno,
    bonus_data( ii ).ename,
    bonus_data( ii ).job,
    bonus_data( ii ).sal,
    bonus_data( ii ).comm;
    EXIT WHEN bonselect%NOTFOUND;
    ii := ii + 1;
    END LOOP;
    END bonus_query;
    PROCEDURE bonus_refcur(bonus_data IN OUT b_cursor) IS
    BEGIN
    OPEN bonus_data FOR SELECT empno, ename, job, sal, comm FROM bonus_EMP ORDER BY empno;
    END bonus_refcur;
    END bonus_pkg;
    i want to populate the data in forms manually not using forms data block wizard and programmatically.
    please reply...

    Can anyone give me an example of a scenario where we need to create a form manually based on a database stored procedures.Typically, you would use a procedure based block when you have a collection of data from multiple tables presented in a Form and your user needs to be able to update the information displayed.
    From your code example, it looks like you are using Oracle Support document "Basing a Block on a Stored Procedure - Sample Code [ID 66887.1]". If this is the case, keep following the document - it walks you through all of the steps. There is no need to Manually configure things that the Data Block Wizard will perform for you!
    i want to populate the data in forms manually not using forms data block wizard and programmatically. Why? Let the Data Block Wizard take care of configuring your block based on a procedure for you. There is no need to manually loop through the data! I've actually done what you are attempting and it was more work than was needed. Let Forms do the work for you. :)
    If you absolutely must do things manually, I recommend you use the PROCEDURE bonus_query(bonus_data IN OUT bontab) instead of the bonus_refcur(bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB and then call the bonus_query procedure. Then it is a simple case of looping through the table of records returned by the bonus_query procedure. For example:
    DECLARE
       t_bonus    bonus_pkb.bontab;
    BEGIN
       bonus_pkg.bonus_query(t_bonus);
       FOR i in 1 .. t_bonus.count LOOP
          :YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno;
          :YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename;
          :YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job;
          :YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal;
          :YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm;
       END LOOP;
    END;This code sample demonstrates the basics, but as it is sample code - you will have to adapt it to your situation.
    Also, I strongly recommend you look at the article InoL listed. This is a very comprehensive discussion on REF CURSORs. If you are set on using a procedure based data source - it is more efficient to pass the table of records back to your form than it is to pass a ref cursor. Using a ref cursor, you might as well just using a standard named cursor and loop through your named cursor. The effect is the same (one row returned at a time creating lots of network traffic). Using the table of records is more efficient because the entire data set is returned so network traffic is reduced.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Fetch Ref Cursor Multiple Times

    create or replace
    PROCEDURE refcursor1
    AS
    TYPE r_cursor IS REF CURSOR;
    rcv_emp r_cursor;
    TYPE rec_emp IS record
    empno NUMBER,
    ename VARCHAR2(20 CHAR),
    deptno number
    recv_emp rec_emp;
    recv_emp2 rec_emp;
    PROCEDURE printemployeedetails AS
    BEGIN
      loop
      fetch rcv_emp INTO recv_emp;
      exit WHEN rcv_emp%notfound;
        dbms_output.put_line(recv_emp.empno||'-'||recv_emp.ename||'-'||recv_emp.deptno);
      END loop;
    END;
    PROCEDURE printemployeedetails2(p_emp r_cursor) IS
    BEGIN
      loop
      fetch p_emp INTO recv_emp2;
      exit WHEN p_emp%notfound;
        dbms_output.put_line(recv_emp2.empno||'-'||recv_emp2.ename||'-'||recv_emp2.deptno);
      end loop;
    END;
    BEGIN
      FOR i IN (SELECT deptno FROM dept order by deptno)
      loop
        OPEN rcv_emp FOR SELECT empno,ename,deptno FROM emp WHERE deptno=i.deptno;
        dbms_output.put_line(i.deptno);
        dbms_output.put_line('--------------------');
        dbms_output.put_line('calling printemployeedetails');
        printemployeedetails;
        dbms_output.put_line('                    ');
        dbms_output.put_line('calling printemployeedetails2');
        dbms_output.put_line('                    ');
        printemployeedetails2(rcv_emp);
        CLOSE rcv_emp;
      END loop;
    end;
    Output:
    10
    calling printemployeedetails
    7839-KING-10
    7782-CLARK-10
    7934-MILLER-10
    calling printemployeedetails2
    20
    calling printemployeedetails
    7566-JONES-20
    7788-SCOTT-20
    7902-FORD-20
    7369-SMITH-20
    7876-ADAMS-20
    calling printemployeedetails2
    30
    calling printemployeedetails
    7698-BLAKE-30
    7499-ALLEN-30
    7521-WARD-30
    7654-MARTIN-30
    7844-TURNER-30
    7900-JAMES-30
    calling printemployeedetails2
    40
    calling printemployeedetails
    calling printemployeedetails2
    Hello All,
    If i open a cursor once can i fetch the elements of a cursor n times like above? i see only either one of those procedures are printing the details but not both.
    Wonder why as i am passing the same ref cursor to a second procedure.
    It's neither throwing me an error saying the elements of ref cursor are already fetched.
    Thank you.

    >
    If i open a cursor once can i fetch the elements of a cursor n times like above? i see only either one of those procedures are printing the details but not both.
    Wonder why as i am passing the same ref cursor to a second procedure.
    It's neither throwing me an error saying the elements of ref cursor are already fetched.
    >
    You can't see any such thing. That code above won't even compile let alone run.
    The 'ref cursor' you are talking about is defined in a standalone procedure 'refcursor1' which does NOTHING but declare some variables that are then NEVER USED.
    The other procedures try to use variables that DO NOT EXIST since they are not declared in the procedure that is trying to use them. So those procedures won't compile and even if they did compile and run each execution only does ONE fetch so the anonymous block can't possibly produce multiple rows of output.  
    I don't know what you claim to be seeing but it certainly isn't anything produced by the code you posted.

  • How to create table from ref cursor

    I have a proc that returns a ref cursor, whats the simplest way to create a table based on the return of the ref cursor?
    declare
    type rc is ref cursor;
    p_data rc;
    begin
    call_my_proc(p_data);
    :result := p_data; -- If I run this in TOAD I can see the data here but I want to create a table based on it rather than outputting it)
    end;
    thanks.
    edit: sorry. typed this wrong first time, should be right now

    961469 wrote:
    I have a proc that returns a ref cursor, whats the simplest way to create a table based on the return of the ref cursor?Not to do it...
    A cursor is not a result set. A cursor is not a result set. Worth repeating several times as this is a common misconception
    A cursor is essentially a program. Executable code that was compiled from a SQL source code program.
    A SELECT cursor is "read" program. Each fetch instruction runs this program (from its current "paused state"), and outputs data.
    An INSERT cursor is a "write" program. You pass data to it (process called binding, via bind variables). You then execute the program. It writes the data it received (can be bulk data via a bulk bind) to table.
    Now your question is: How do I write the output of a cursor program back to the database?
    The answer is that a "write" cursor program is needed. Your code needs to execute (fetch output from) the ref (read/select) cursor. Then bind that data to the "write" cursor and execute it.
    In other words, you have a read cursor and a write cursor, and you need to pass data from one to the other.
    HOWEVER.. This is slow. This does not scale. This is also known as slow-by-slow row by row processing.
    The correct approach is to create a single program. One that reads the data, and then writes the data. No to send data via a detour through your code between the read part and write part.
    The cursor to create is an INSERT..SELECT cursor. This can do fast direct path inserts. This can be executed in parallel - i.e. the database executing several copies of this read-and-write program at the same time.

  • Cast error message when discovering ref cursor parameter from stored proced

    We are today using Microsoft's Oracle provider with some code from the old Data Application Block (from MSDN) to discover parameters from the stored procedures. This code uses the OracleCommandBuilder.DeriveParameters to get the parameters from the stored procedure and command.Parameters.CopyTo copies the discovered parameters into the command object.
    If I test with a simple function returning a ref cursor I get one parameter with type refCursor and ParameterDirection.OutPut. This is working fine as long we where using Microsoft's Oracle provider. But using Oracle ODP .NET I get the following error message on datadapter.Fill (I fill a dataset with the result from the reference cursor)
    Unable to cast object of Type 'Oracle.DataAccess.Client.OracleDataReader' to type 'Oracle.DataAccess.Types.OracleRefCursor.
    If I create a ref parameter manualy like this:
    OracleParameter myrefCursor = new OracleParameter();
    myrefCursor .OracleDbType = OracleDbType.RefCursor;
    myrefCursor .ParameterName = "myParameterName";
    myrefCursor .Direction = ParameterDirection.ReturnValue;
    and add it to the command object this is working OK. So it seems to be a problem with discovering ref cursor parameters from the database, other parameter types is OK.. I have compared the properties of my manual ref cursor parameter with the one discovered from the stored procedure, but I cannot see any difference. (I see the Value property has some values for the discovered one, but I have set this to DBNull.Value without any result)
    Any ideas why I get this error code? Is there any other code blocks I can use to discover the parameters? We send in params object[] with the different values into the helper class and the value is added to the parameter. (Se I don't need to set the data type etc for each parameter, I just need to have the correct order of the parameters)

    For accuracy's sake, just wanted to let everyone know that this is actually a bug. The correct bug number is 8423178.
    Christian
    Mark_Williams wrote:
    Just to follow-up on this issue...
    The bug has been closed as "not a bug" as it seems undocumented behavior was relied upon for this to work in earlier releases.
    Note from the documentation on DeriveParameters:
    "The output values of derived parameters return as .NET Types by default. To obtain output parameters as provider types, the OracleDbType property of the parameter must be set explicitly by the application to override this default behavior. One quick way to do this is to set the OracleDbType to itself for all output parameters that should be returned as provider types." (emphasis added)
    The issue, as you might already know, is that there is no corresponding .NET Framework Type for an Oracle Ref Cursor and the type is, therefore, set to Object. So, explicitly setting the type to OracleDbType.RefCursor should work.
    Regards,
    Mark

  • Passing value to ref cursor

    Hi,
    I have a doubt in the code mentioned below ..indicated in the code by
    " -- id shoud be the value fetched from variable v_samp;".
    I am not sure of how I get the value into the ref cursor from the variable
    declare
    Cursor C1
    Is Select Table_Name,Rownum R_Num From User_Tables Where Table_Name Like 'T%' Order By Table_Name;
    Cursor C2 Is Select Sample From code_tbl;
    Type Ref1 Is Ref Cursor;
    R_1 Ref1;
    Type T_Samp Is Table Of Varchar2(100);
    Lv_Samp T_Samp;
    lv_geno T_Samp;
    Begin
    For L1 in C1 loop
    V_tbl := L1.table_name;
    For L2 In C2 Loop
    V_samp := L2.sample;
    Open R_1 for 'Select sample_id, genotype from ' || V_tbl || ' where id = ? '; -- id shoud be the value fetched from variable v_samp;
    Loop
    Fetch R_1 Bulk Collect Into Lv_Samp,Lv_Geno Limit 10000;
    FOR indx IN 1 .. lv_samp.COUNT
    Loop
    V1 := V1 || lv_geno(indx);
    End Loop;
    EXIT WHEN Lv_samp.COUNT = 0;
    end loop;
    end loop;
    end loop;
    end;
    Thanks

    Sorry about my approach..I did that using tool. I don't know how to keep it..I do apologize if I did hurt you..
    This is my complete requirement...
    For every sample in table all_f if it exists in table t1
    then the output should be the concatenated value of type
    for the corresponding sample. Let me know if I need to do anything else..There are million types for every sample.
    The output should be
    'AB35652626-G8' 1 1 1 1 1 1 1 1 1 1 0 0
    since only this id exists in c3 (table t1).
    This is just a sample...I have huge number of rows to be concatenated for multiple id's.
    So that is the reason why I don't want to do any processing in the loop except concatenation.
    DDL's and DML's are as follows :
    create table all_f (sample varchar2(20), typeo varchar2(20));
    insert into all_f (SAMPLE, typeo)
    values ('AB35053903-C10', '2');
    insert into all_f (SAMPLE, typeo)
    values ('AB35053995-A10', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35054283-C3', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35054582-A7', '2');
    insert into all_f (SAMPLE, typeo)
    values ('AB35055053-H12', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35055158-B2', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35500856-F4', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35501332-G11', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35501428-B9', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35504972-F11', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35505551-H7', '2');
    insert into all_f (SAMPLE, typeo)
    values ('AB35506138-G5', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35507097-C11', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35507190-G9', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35561723-H10', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35651275-E6', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35896175-C8', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35897805-A3', '2');
    insert into all_f (SAMPLE, typeo)
    values ('AB35899249-H8', '1');
    insert into all_f (SAMPLE, typeo)
    values ('AB35899918-H6', '1');
    insert into t1 (SAMPLE, TYPEO)
    values ('AB35652626-G8', '1');
    commit;
    create table t1 (sample_id varchar2(20), type varchar2(20));
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '1');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '0');
    insert into t1 (SAMPLE_ID, TYPE)
    values ('AB35652626-G8', '0');
    Thanks,

  • Ref Cursor closed returning to Form

    Hi,
    I came across this old thread which seems to be an exact match for my problem.
    sys ref cursor is closed
    And whereas the solutions do work as stated there is an issue with it that i wonder if anyone here has since got around.
    Take those examples and make the sql dynamic. on return to the form the ref cursor is instantaneouly closed for you making the thing unusable.
    i.e.
    OPEN cur FOR SELECT 'x' from dual
    works just fine but
    OPEN cur FOR 'SELECT ''X'' from dual'
    resutls in an closed cursor the moment the ref cursor parameter returns to the form. I need the dynamic form because my cursor is truly built dynamically.
    Any ideas anyone?

    Hi,
    try this :
    1. declare in the package specification
    TYPE rec_view IS RECORD(
      COL1        VARCHAR2(250),
      COL2        VARCHAR2(250),
      COL3        VARCHAR2(250),
      COL4        VARCHAR2(250),
      COL5        VARCHAR2(250)
      TYPE t_ref_curs IS REF CURSOR RETURN rec_view;
      TYPE t_rec_c IS REF CURSOR;
    2. define the dynamic sql - procedure
    PROCEDURE   prc_getdata (p_refcur IN OUT t_ref_curs, p_result OUT VARCHAR2,
                             p_filter IN varchar2 DEFAULT NULL, p_orderby In VARCHAR2 DEFAULT NULL)  IS
      BEGIN
            -- dyn cursor ! --
            EXECUTE IMMEDIATE
                    'BEGIN
                          OPEN :a FOR ' ||
                              ' select empno, ename, job, mgr, hiredate, sal  from emp'||' '||
                                p_filter  ||' '||
                                p_orderby ||'; '||
                     'END;'
               USING p_refcur;
       END prc_getdata;
    3. define in the Form a PL/SQL based block on this procedure.
    Hope it helps.
    Best regards
    Friedhold

  • Difference Ref cursor with/with out using clause

    Hi everyone,
    When I am using dynamic sql with USING clause ,the results are not sorted in Ascending order.
    DECLARE
    TYPE emp_refcursor IS REF CURSOR;
    emp_rc emp_refcursor;
    TYPE v_emp_id IS TABLE OF number INDEX BY PLS_INTEGER;
    TYPE v_last_name IS TABLE OF varchar2(50) INDEX BY binary_integer;
    V_empno v_emp_id;
    v_ename v_last_name;
    p_deptno number := &U_DEPTNO;
    v_limit number := 10;
    v_ordcolumn varchar2(20) := 'employee_id';
    v_stmt varchar2(1000);
    BEGIN
    v_stmt :=
    'select employee_id,last_name from employees
    where department_id = :x order by :y ';
    dbms_output.put_line(v_stmt);
    OPEN emp_rc FOR v_stmt USING p_deptno,v_ordcolumn;
    LOOP
    FETCH emp_rc BULK COLLECT INTO v_empno,v_ename LIMIT v_limit;
    EXIT WHEN v_empno.count = 0;
    FOR I IN v_empno.first .. v_empno.last
    LOOP
    dbms_output.put_line(v_empno(i)||' '||v_ename(i));
    END LOOP;
    END LOOP;
    END;
    When I use dynamic sql with out USING cluase,results are sorted in Ascending order.
    DECLARE
    TYPE emp_refcursor IS REF CURSOR;
    emp_rc emp_refcursor;
    TYPE v_emp_id IS TABLE OF number INDEX BY PLS_INTEGER;
    TYPE v_last_name IS TABLE OF varchar2(50) INDEX BY binary_integer;
    V_empno v_emp_id;
    v_ename v_last_name;
    p_deptno number := &U_DEPTNO;
    v_limit number := 10;
    v_ordcolumn varchar2(20) := 'employee_id';
    v_stmt varchar2(1000);
    BEGIN
    v_stmt :=
    'select employee_id,last_name from employees
    where department_id = '||p_deptno ||
    ' order by '||v_ordcolumn;
    dbms_output.put_line(v_stmt);
    OPEN emp_rc FOR v_stmt;
    LOOP
    FETCH emp_rc BULK COLLECT INTO v_empno,v_ename LIMIT v_limit;
    EXIT WHEN v_empno.count = 0;
    FOR I IN v_empno.first .. v_empno.last
    LOOP
    dbms_output.put_line(v_empno(i)||' '||v_ename(i));
    END LOOP;
    END LOOP;
    END;
    P.S :---- department_id (used) = 50;
    Please can some one explain why this is happening like this.
    Thanks
    Raghu
    --------------------------------------------------------------------------------

    Hi sundar,
    I am new to oracle and learning/trying to get the same output by using differnt methods,rather than using FOR LOOP ,I tried to use ref cursor with dynamic sql.I am in a belief that ref cursor's with dynamic sql are faster than FOR LOOP,irrespective of the size of data.Can you correct me if I am wrong.
    Coming back to ur reply,how should my statement look like,when using ref cursor
    with USING claus to sort data by asc/desc order.
    Thanks in advance
    Raghu

  • Help on REF Cursors

    Hi Folks,
    When i try to run the following piece of code i get errors saying :
    PLS-0221 : emp_cursor is not a procedure or is undefined
    PLS-00382 : expression is of the wrong type
    can you please help me figure out what is going wrong here ?
    Thanks very much in advance.
    Moses.
    declare
    /* REF Cursor for employee */
    emp_rec employee%ROWTYPE;
    TYPE EmpCurTyp IS REF CURSOR RETURN emp_rec%TYPE;
    emp_cursor EmpCurTyp;
    emp_id NUMBER;
    cursor dept_cursor is
    select distinct dept_id from dept;
    dept_rec dept_cursor%ROWTYPE;
    dep_id VARCHAR2(20);
    begin
    /* dept loop */
    for dept_rec in dept_cursor
    loop
    dep_id := dept_rec.dept_id;
    /* get employees for this dept */
    OPEN emp_cursor FOR
    select distinct emp_id from employee
    where dept_id = dep_id;
    /* employee loop */
    for emp_rec in emp_cursor
    loop
    emp_id := emp_rec.employee_id;
    '

    Hi Moses,
    looking at Yr code, I guess that the problem may be that You OPEN emp_cursor and after that You reopen the same cursor with the FOR statement.
    Try rewriting the LOOP in this way:
    OPEN emp_cursor FOR
    SELECT DISTINCT emp_id
    FROM employee
    WHERE dept_id = dep_id;
    FETCH emp_cursor INTO emp_record
    WHILE emp_cursor%FOUND
    LOOP
    -- Yr code here
    FETCH emp_cursor INTO emp_record;
    END LOOP;
    CLOSE emp_cursor;You can also convert the usage of the REF syntax using cursor variables.
    Hope thi helps
    Bye Max
    null

  • Iterate thru ref cursor received from Procudure

    Hi All,
    I have a proc X that has an Out parameter as ref cursor.
    I am calling that proc in another proc Y now how do i iterate through the ref Cursor returned.(in which data type shall i fetch the record of that ref cursor)
    Regards
    Arpit

    Arpit wrote:
    I have a proc X that has an Out parameter as ref cursor.
    I am calling that proc in another proc Y now how do i iterate through the ref Cursor returned.(in which data type shall i fetch the record of that ref cursor)The "data type" (known as the SQL projection) of the ref cursor depends on the SQL statement executed. That can be totally dynamic and unknown for a ref cursor until run-time - which means there is no way for your static PL/SQL code to know what the projection is and how to fetch it.
    Which is why ref cursors are VERY SELDOM used in PL/SQL..
    Ref cursors are intended to be consumed by external Oracle client processes - not PL/SQL. A DBMS_SQL cursor is to PL/SQL what a ref cursor is to an external client.
    Consuming ref cursors in PL/SQL code is unusual - and should be treated as an exception. And this asks the question what are your reasons for writing PL/SQL code that consumes a ref cursor?

  • Stored PL/SQL function that returns REF CURSOR type

    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by angelrip:
    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel<HR></BLOCKQUOTE>
    Do something like the following:
    cstmt = conn.prepareCall("{call customer_proc(?, ?)}");
    //Set the first parameter
    cstmt.setInt(1, 40);
    //Register to get the Cursor parameter back from the procedure
    cstmt.registerOutParameter(2, OracleTypes.CURSOR);
    cstmt.execute();
    ResultSet cursor = ((OracleCallableStatement)cstmt).getCursor(2);
    while(cursor.next())
    System.out.println("CUSTOMER NAME: " + cursor.getString(1));
    System.out.println("CUSTOMER AGE: " + cursor.getInt(2));
    cursor.close();
    null

Maybe you are looking for

  • Need help with iphoto and dragging to external hard drive

    Hello, I have my iphoto very organized into Events and I recently just moved them to be in folders.  I would like to have only certain Events (or folders/albums) on the external hard drive.  The apple store rep said to go to Finder, Pictures, Iphoto,

  • How to get notified about new post created for Oracle istore

    I want be active part of post created in iStore or EBS. How can I get immediately get notified (email) about new post created in iStore or EBS (OTN Forum)? Currently I get immediate email about post that I am watching ie post I created or if someone

  • How to allow audio download of podcast

    How can we make it so visitors to our podcast page can download a podcast without having to subscribe to our podcast?

  • Oracle Streams PIT on Source DB

    I'm testing backup/recovery in my streams environment, simulating a PITR on the source. The objective is to get both the source and destination to the same point in time, driven by the source. That being said, if recover to a time 5 hours prior, on b

  • Photoshop Elements 11 Slide Show

    I created a slide show (actually 3) with audio and saved it. Now I can't locate it. I have tried everything. I must be overlooking some setting. I thought it would appear in it's own folder. Any help will be greatly appreciated.