Using rowid in ref cursor

Hi,
I want to use rowid for updating the rows in the ref cursor. My code looks like below:
DECLARE
emp_refcursor SYS_REFCURSOR;
emp_rec employee%ROWTYPE;
l_run_id NUMBER;
lv_sql_stmt VARCHAR2(4000) := 'SELECT a.* FROM employee a where a.run_id = :l_run_id ';
OPEN emp_refcursor FOR lv_sql_stmt
USING l_run_id;
LOOP
FETCH emp_refcursor
INTO emp_rec;
EXIT WHEN emp_refcursor%NOTFOUND;
Here in lv_sql_stmt I want to include the rowid also so that I can use the update statement with the rowid. I cant directly add the rowid in the query as I am fetching the records in emp_rec which is of the rowtype of table EMPLOYEE.
I want to use rowid for making the fetching of records faster.
Please suggest e some ways to implement it.
Thanks.
Edited by: user12841217 on Mar 23, 2010 12:12 AM

user12841217 wrote:
Hi,
I want to use rowid for updating the rows in the ref cursor.There are no rows in a ref cursor. Read the following:
PL/SQL 101 : Understanding Ref Cursors :-
PL/SQL 101 : Understanding Ref Cursors
My code looks like below:
DECLARE
emp_refcursor SYS_REFCURSOR;
emp_rec employee%ROWTYPE;
l_run_id NUMBER;
lv_sql_stmt VARCHAR2(4000) := 'SELECT a.* FROM employee a where a.run_id = :l_run_id ';
OPEN emp_refcursor FOR lv_sql_stmt
USING l_run_id;
LOOP
FETCH emp_refcursor
INTO emp_rec;
EXIT WHEN emp_refcursor%NOTFOUND;
Here in lv_sql_stmt I want to include the rowid also so that I can use the update statement with the rowid. I cant directly add the rowid in the query as I am fetching the records in emp_rec which is of the rowtype of table EMPLOYEE.
I want to use rowid for making the fetching of records faster.
Please suggest e some ways to implement it. This sounds like half of the requirement. If you're already fetching the rows using your ref cursor, then why would you need the rowid to fetch them again?
If you really need to include rowid in your query then you're going to have to fetch into a known defined structure rather than employee%ROWTYPE. This is what we call in the business... "design", which is usually based on "requirements". Know your requirements and implement a suitable design accordingly. A good design would seldom be selecting "*" within any query, as a good design would actually know what data is expected to be fetched.

Similar Messages

  • Using Ref cursor in Procedure.

    Hi All,
    Can i use a single ref cursor multple times within the life cycle of a procedure.
    Thanks,
    Dillip

    Yes.
    See the example here. A cursor expression is selected - repeatedly, within a loop - into emp_cur (which is of type REF CURSOR) - and emp_cur is then used to process it in a nested loop.
    (By the way - this question would be better asked in the PL/SQL).
    Regards Nigel

  • Using bind variable for ref cursors

    Hi
    I have a procedure that recieves a tablename in srcTable variable . A query is formed SELECT_Q with values from global varray.
    Table name will be dynamic and query is to be used with a ref cursor. Since table name is not known how to make the refcursor.
    tried the following.....not sure how to do it. pls help.
    PROCEDURE Process1(srcTable VARCHAR2, trgTable VARCHAR2) IS
         TYPE CURSORTYPE IS REF CURSOR RETURN :x%ROWTYPE;
         REC_CUR CURSORTYPE;
         REC_CUR_DATA :x%ROWTYPE;
         DBMS_SQL.BIND_VARIABLE(REC_CUR, ':x', SourceT);
         DBMS_SQL.BIND_VARIABLE(REC_CUR_DATA, ':x', SourceT);
         COUNTi NUMBER :=0;
         SELECT_Q VARCHAR2(1000) := 'SELECT ';
    BEGIN
    FOR COUNTi IN 1..COLUMN_NAME_ARR.COUNT-1 LOOP
              SELECT_Q := SELECT_Q || COLUMN_NAME_ARR(COUNTi) || ',';
    END LOOP;
         SELECT_Q := SELECT_Q || COLUMN_NAME_ARR(COLUMN_NAME_ARR.COUNT) || ' FROM '||SourceT;
         DBMS_OUTPUT.PUT_LINE(SELECT_Q);
    -- query to be used for making cursor.
    ---how to make the cursor
         OPEN REC_CUR FOR Select_Q;
         LOOP
         FETCH REC_CUR INTO REC_CUR_DATA;
         EXIT WHEN REC_CUR%NOTFOUND;
         END LOOP;
    END TableSnapShot_Process1;

    For online books you can start with the documentation.
    PL/SQL Packages and Types Reference
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/toc.htm
    PL/SQL User's Guide and Reference
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
    Print books
    Oracle PL/SQL Programming By Steven Feuerstein is good book to have.
    http://www.oreilly.com/catalog/oraclep4/

  • Ref cursors and dynamic sql..

    I want to be able to use a fuction that will dynamically create a SQL statement and then open a cursor based on that SQL statement and return a ref to that cursor. To achieve that, I am trying to build the sql statement in a varchar2 variable and using that variable to open the ref cursor as in,
    open l_stmt for refcurType;
    where refcurType is a strong ref cursor. I am unable to do so because I get an error indication that I can not use strong ref cursor type. But, if I can not use a strong ref cursor, I will not be able to use it to build the report based on the ref cursor because Reports 9i requires strong ref cursors to be used. Does that mean I can not use dynamic sql with Reports 9i ref cursors? Else, how I can do that? Any documentation available?

    Philipp,
    Thank you for your reply. My requirement is that, sometimes I need to construct a whole query based on some input, and sometimes not. But the output record set would be same and the layout would be more or less same. I thought ref cursor would be ideal. Ofcourse, I could do this without dynamic SQL by writing the SQL multiple times if needed. But, I think dynamic SQL is a proper candidate for this case. Your suggestion to use lexical variable is indeed a good alternative. In effect, if needed, I could generate an entire SQL statement and place in some place holder (like &stmt) and use it as a static SQL query in my data model. In that case, why would one ever need ref cursor in reports? Is one more efficient over the other? My guess is, in the lexical variable case, part of the processing (like parsing) is done on the app server while in a function based ref cursor, the entire process takes place in the DB server and there is probably a better chance for re-use(?)
    Thanks,
    Murali.

  • Dyn SQL in Ref cursor?

    Hi all,
    I have a pkg as below and its err message in compile:
    create or replace PACKAGE PKG_DARTS1 is
    TYPE TY_PARTY_DETAIL1 IS RECORD (
         PTY_TYPE xxx.yyyy%TYPE
    TYPE cur_partydetail1 IS REF CURSOR RETURN TY_PARTY_DETAIL1;
    procedure SP_GetPartyDetail1(     c_partydetail1 OUT pkg_darts1.cur_partydetail1) ;
    end PKG_DARTS1;
    create or replace PACKAGE BODY PKG_DARTS1 as
    procedure SP_GetPartyDetail1(     c_partydetail1 OUT pkg_darts1.cur_partydetail1)
    AS
         sql_stmt VARCHAR2(2000);
    BEGIN
         sql_stmt := 'select ''XXX'' FROM DUAL ';
         OPEN c_partydetail1 FOR sql_stmt;
    EXCEPTION
         WHEN OTHERS THEN
              dbms_output.put_line(sqlerrm);
    END SP_GetPartyDetail1;
    END PKG_DARTS1;
    .Warning: Package Body created with compilation errors.
    Errors for PACKAGE BODY PKG_DARTS1:
    LINE/COL ERROR
    13/3 PL/SQL: Statement ignored
    13/8 PLS-00455: cursor 'C_PARTYDETAIL1' cannot be used in dynamic SQL
    OPEN statement
    what's wrong with my syntax? anything I should care in constructing sql in ref cursor?
    thx,
    bean

    You can't use strongly types ref cursors with dynamic SQL, you will have to use weakly typed.
    Hth
    Martin

  • Ref Cursor Query

    I was exploring the use of a ref cursor query within my report. The question that I have is do you have to put the package in the reports program units or can you place the package on the db server and call the package?

    Hi,
    You can do it both ways.
    Regards
    Kamal

  • REF cursor with special characters

    Hi all,
    I want to display the record set using ref cursor. I am passing varchar field as parameter. How to give this in where cluase of select statement.
    i want to use like %parameter_name% in where condition. How to use it in ref cursor.
    Thanks in advance,
    Pal

    user546710 wrote:
    Hi all,
    I want to display the record set using ref cursor. I am passing varchar field as parameter. How to give this in where cluase of select statement.
    i want to use like %parameter_name% in where condition. How to use it in ref cursor.
    Thanks in advance,
    PalWhy using a ref cursor? Do you understand the purpose of ref cursors and how to use them?
    Perhaps take a read of the following to get to grips with the basics...
    PL/SQL 101 : Understanding Ref Cursors
    PL/SQL 101 : Understanding Ref Cursors

  • Return csv string as strongly typed ref cursor

    I have a column in a table that is csv delimited and I want to return it (and others) as a strongly typed ref cursor.
    eg
    create table test_tab (mydata varchar2(100))
    insert into test_tab(mydata) values ('"a1","b1","c1","d1"')
    insert into test_tab(mydata) values ('"a2","b2","c2","d2"')
    so test_tab has 1 column and 2 rows:
    "a1","b1","c1","d1"
    "a2","b2","c2","d2"
    So a,b,c,d represent columns in my strongly typed ref cursor
    If I then try something like:
    declare
    type my_rec is record(
    a varchar2(50),
    b varchar2(50),
    c varchar2(50),
    d varchar2(50)
    type my_rec_refc IS REF CURSOR RETURN my_rec;
    my_test_refc my_rec_refc;
    begin
    open my_test_refc for select mydata,mydata,mydata,mydata from test_tab;
    end;
    then it obviously works as my ref cursor is expecting 4 columns. However, what I want to do is break each individual element out of the mydata column. I've played around a bit with dynamic sql but only getting so far and apparently that can't be used with a ref cursor anyway. I need to return a strongly typed cursor as another program requires this.
    One option is to manually parse each row and insert into temp table that is basically definition of record (so record type no longer needed) and this becomes type of ref cursor. I can then simply select from the table. I'm not keen on this as it's just another object to worry about.
    Another option is to do some ugly instr/substr to extract each element in the sql statement (or write a function to do it but need to consider performance of this). The more generic the better as I need to reuse against multiple strongly typed ref cursors (kind of a contradiction in that by virtue of using strongly typed cursors I know exactly what I want returned!).
    Another option is for someone to shed some light on this as it must be possible to do in a simple way along the same lines I have started?
    thanks in advance

    That documentation seems to stay pretty vague. What constitutes the "right set of columns". Obviously my observed result matches what you are saying about not being able to enforce the datatypes in the fields of the strong typed cursor. But then I don't see the point of the strong typed cursor otherwise. Other sites i have read seem to focus on the %rowtype return rather than mapping it to a record. But the general consensus (at least to my understanding) is that if the cursor is strongly typed then the sql statement that used to open it must have the same set of columns and the datatypes must at least be able to implicitly convert.
    I will try the %rowtype strong ref cursor against a table and see if there is a different result. I am mainly interested in this because I would like to beable to ensure the datatype returned on the .net side through ODP
    I want to be able to know the datatype of a field coming back through a ref cursor at compile time not runtime. So it the answer to cast every field of the select statement?

  • Stored procedure and ref cursor problem

    I am trying to create a stored procedure that can be used in Crystal Reports. To do this I have to create a package and a ref cursor. My SQL is below:
    --Package
    Create or Replace Package Test_Package
    as type test_type is ref cursor;
    end;
    --Procedure
    Create or Replace Procedure Test_Proc
    (test_cursor in out test_package.test_type,
    parameter in string
    as
    begin
    open test_cursor for
    select ClientName from apbpman.cv_client where clientref = parameter;
    end;
    --When trying to execute the SP in Oracle I use:-
    set serveroutput on
    declare
    test_cursor apbpman.test_package.test_type;
    resultset test_cursor%rowtype;
    begin
    apbpman.test_proc(test_cursor,'0096');
    if not test_cursor%isopen then
    dbms_output.put_line ('OK');
    else
    dbms_output.put_line ('Not OK');
    end if;
    fetch test_cursor into resultset;
    while test_cursor%found loop
    dbms_output.put_line(resultset.ClientName);
    fetch test_cursor into resultset;
    end loop;
    end;
    Whenever this runs I receive the following error reports:
    resultset test_cursor%rowtype;
    ERROR at line 3:
    ORA-06550: line 3, column 13:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 3, column 13:
    PL/SQL: Item ignored
    ORA-06550: line 11, column 25:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 11, column 2:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 13, column 24:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 13, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 14, column 26:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 14, column 3:
    PL/SQL: SQL Statement ignored
    I have tried in vain to find a resolution to this but have failed. Please help.
    Thanks,
    Paul

    Unless you are running a really old version of Oracle, any weak ref cursor can just be declared SYS_REFCURSOR. Also, you can't use a weak ref cursor for %ROWTYPE. You can test the procedure in SQL*Plus by using it to populate a refcursor variable.

  • Ref cursor returns login ids

    I have this ref cursor that returns login ids from a procedure.
    While I can define the ref cursor as sys_refcursor; I want to use strongly typed ref cursor ( for improved readabilty of code).
    But I guess I can not define the cursor that returns %type.
    e.g. Type return_login_id IS REF CURSOR return tab1.login_id%type;
    On compilation the package threw an error saying the return type should be record.
    I need to define a record with one column and use that as return type ?
    any other way around ?
    TIA
    S

    Btw, why you need to use REF Cursor?
    You can use just a cursor:
    SQL> declare
      2  cursor c1 is select empid from emp;
      3  TYPE my_id IS TABLE OF emp.empid%type;
      4  myid my_id := my_id();
      5  BEGIN
      6  OPEN c1;
      7  FETCH c1 BULK COLLECT INTO myid;
      8  CLOSE c1;
      9  END;
    10  /
    PL/SQL procedure successfully completed.
    SQL>

  • How to access variable number of columns using ref cursor !

    Hi,
    I am trying to get variable number of columns using ref cursor.
    Declare
    mySzSql varchar2(2000);
    Type dynSqlRC is Ref cursor;
    current_cur dynSqlRC;
    tbl_rec alt_42_consolidated%Rowtype;
    Begin:
    /* This works */
    mySzSql := 'select *
    from
    Table1
    Where
    rowid = ''AAEWNEABXAAAAkxAAA''';
    /* i want something like this to work, this is not working, giving missing variable name error */
    mySzSql := 'select col1, col2, col3
    from
    Table1
    Where
    rowid = ''AAEWNEABXAAAAkxAAA''';
    open current_cur for mySzSql;
    fetch current_cur into tbl_rec;
    close current_cur;
    End;
    I do have the list of desired columns which I am looking to fetch, so after taking that in the record type, how should i get their values. Is it possible to traverse tbl_rec declared above and if column name matches then I will store the value in the array and finally return this array.
    Can somebody please tell me how to do this.
    Thanks

    It appears that this is a followup to How to loop through columns selected by select clause which is itself a followup to [url="
    How to execute dynamic sql"]this earlier thread.
    Assuming these are intended to be followup questions, can we please stick to a single thread? That makes it a lot easier to understand the situation and follow the conversation. Starting multiple threads makes it harder to follow the conversation.
    Thanks,
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Report using ref cursor or dynamic Sql

    Hi,
    I never create a report using a ref cursor or a dynamic sql. Could any one help me to solve the below issue.
    I have 2 tables.
    1. Student_Record
    2. Student_csv_help
    Student_Record the main table where the data is stored.
    Student_csv_help will contain the all the column names of the Student_record.
    CREATE TABLE Student_CSV_HELP
    ENTRY_ID NUMBER,
    RAW_NAME VARCHAR2(40 BYTE),
    DESC_NAME VARCHAR2(1000 BYTE),
    IN_OUTPUT_LIST VARCHAR2(1 BYTE)
    SET DEFINE OFF;
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (1, 'S_ID', 'Student ID', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (2, 'S_Name', 'Student Name', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (3, 'S_Join_date', 'Joining Date', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (4, 'S_Address', 'Address', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (5, 'S_Fee', 'Tution Fee', 'N');
    commit;
    CREATE TABLE Student_record
    S_ID NUMBER,
    S_Name VARCHAR2(100 BYTE),
    S_Join_date date,
    S_Address VARCHAR2(360 BYTE),
    S_Fee Number
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (101, 'john', TO_DATE('12/17/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94777', 2000);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (102, 'arif', TO_DATE('12/18/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94444', 3000);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (103, 'raj', TO_DATE('12/19/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94555', 2500);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (104, 'singh', TO_DATE('12/20/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94666', 2000);
    Commit;
    Now my requirement is:
    I have a form with Student_record data block. When i Click on print Button on this form. It will open another window which has Student_CSV_HELP.DESC_NAME and a check box before this.
    The window look like as below:
    check_box       DESC_NAME+
    X                   S_ID+
    --                   S_Name+
    X                   S_Join_date+
    X                   S_Address+
    --                  S_Fee+
    X  means check box checked.+
    --  means check box Unchecked.+
    After i selected these check boxes i will send 2 parameters to the report server
    1. a string parameter to the report server which has the value 'S_ID,S_Join_date,S_Address' (p_column_name := 'S_ID,S_Join_date,S_Address');
    2. the s_id value from the student_record block (p_S_id := '101');
    Now my requirement is when i click on run. I need a report like as below:
    Student ID : 101+
    Joining Date : 12/17/2009 08:00:00+
    Address : CA-94777+
    This is nothing but the ref cursor should run like as below:
    Select S_id from student_record block S_id = :p_S_id;
    Select S_Join_date from student_record block S_id = :p_S_id;
    Select S_Address from student_record block S_id = :p_S_id;
    So, according to my understanding i have to select the columns at the run time. I dont have much knowledge in creating reports using ref cursor or dynamic sql.
    So please help me to solve this issue.
    Thanks in advance.

    Plain sql should satisfy your need. Try ....
    Select S_id, S_Join_date, S_Address
    from student_record
    where S_id = :p_S_id

  • How to retrieve data from a REF CURSOR using OCI 8.0?

    I found an example in Oracle docs (shown below) that discusses how to bind a REF CURSOR for later data retrieval, but it does not explain actually how to do the later data retrieval.
    I hope someone can explain it to me. Thanks
    The OCI provides the ability to bind and define PL/SQL REF CURSORs and nested tables. An application can use a statement handle to bind and define these types of variables. As an example, consider this PL/SQL block:
    static const text plsql_block = (text )
    "begin \
    OPEN :cursor1 FOR SELECT empno, ename, job, mgr, sal, deptno \
    FROM emp_rc WHERE job=:job ORDER BY empno; \
    OPEN :cursor2 FOR SELECT * FROM dept_rc ORDER BY deptno; \
    end;";
    An application would allocate a statement handle for binding, by calling OCIHandleAlloc(), and then bind the :cursor1 placeholder to the statement handle, as in the following code, where :cursor1 is bound to stm2p. Note that the handle allocation code is not included here.
    err = OCIStmtPrepare (stm1p, errhp, (text *) nst_tab, strlen(nst_tab),
    OCI_NTV_SYNTAX, OCI_DEFAULT);
    err = OCIBindByName (stm1p, (OCIBind **) bndp, errhp,
    (text *)":cursor1", (sb4)strlen((char *)":cursor1"),
    (dvoid *)&stm2p, (sb4) 0, SQLT_RSET, (dvoid *)0,
    (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (ub4)OCI_DEFAULT);
    In this code, stm1p is the statement handle for the PL/SQL block, while stm2p is the statement handle which is bound as a REF CURSOR for later data retrieval. A value of SQLT_RSET is passed for the dty parameter.

    ( sorry, i forgot the Link where i get this html fiLes, so i just copy-paste here )
    ( maybe it can heLp you a bit. -- it's heLp me, for sure )
    And the following is thanks to Brett Rosen :
    I noticed that you didn't have an OCI entry
    on http://osi.oracle.com/~tkyte/ResultSets/index.html .
    Here is OCI code to do this (Oracle 81) if you want to include it on
    that page.
    Some error checking and cleanup has been removed, but the below should
    work. (once dbname has been replaced appropriately)
    Brett
    int main(int argc, char* argv[])
    OCIError* pOciError;
    char* pConnectChar = "dbname";
    char* pUsernameChar = "scott";
    char* pPasswordChar = "tiger";
    int answer;
    OCIStmt* pOciStatement;
    char* sqlCharArray = "BEGIN :success := sp_ListEmp; END;";
    int id;
    char ename[40];
    OCIEnv* g_pOciEnvironment = NULL;
    OCIServer* g_pOciServer = NULL;
    OCISession* g_pOciSession = NULL;
    OCISvcCtx* g_pOciServiceContext = NULL;
    sb2* pIndicator=0;
    sb2* pIndicator2=0;
    sb2* pIndicator3=0;
    OCIDefine* pOciDefine;
    OCIDefine* pOciDefine2;
    OCIBind* pBind;
    OCIStmt* cursor;
    answer = OCIInitialize(OCI_THREADED, NULL, NULL, NULL, NULL);
    answer = OCIEnvInit(&g_pOciEnvironment, OCI_DEFAULT, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciSession, OCI_HTYPE_SESSION, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServer, OCI_HTYPE_SERVER, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
    answer = OCIServerAttach(g_pOciServer, pOciError, (unsigned char *)pConnectChar, strlen(pConnectChar),
    OCI_DEFAULT);
    answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pUsernameChar, strlen(pUsernameChar),
    OCI_ATTR_USERNAME, pOciError);
    answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pPasswordChar, strlen(pPasswordChar),
    OCI_ATTR_PASSWORD, pOciError);
    answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciServer, 0, OCI_ATTR_SERVER, pOciError);
    answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciSession, 0, OCI_ATTR_SESSION, pOciError);
    answer = OCISessionBegin(g_pOciServiceContext, pOciError, g_pOciSession, OCI_CRED_RDBMS, OCI_DEFAULT);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&pOciStatement), OCI_HTYPE_STMT, 0, NULL);
    answer = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray, strlen(sqlCharArray),
    OCI_NTV_SYNTAX, OCI_DEFAULT);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&cursor), OCI_HTYPE_STMT, 0, NULL);
    answer = OCIBindByPos(pOciStatement,&pBind, pOciError, 1, &cursor, 0,SQLT_RSET,
    pIndicator2, 0,NULL, 0,0,OCI_DEFAULT);
    answer = OCIStmtExecute(g_pOciServiceContext, pOciStatement, pOciError, 1, 0, NULL, NULL,
    OCI_COMMIT_ON_SUCCESS);
    answer = OCIDefineByPos(cursor,&pOciDefine, pOciError,2,&id,sizeof(int),
    SQLT_INT,pIndicator, 0, 0,OCI_DEFAULT);
    answer = OCIDefineByPos(cursor,&pOciDefine2, pOciError,1,ename,40,
    SQLT_STR,pIndicator3, 0, 0,OCI_DEFAULT);
    if (answer == 0)
    while ((answer = OCIStmtFetch(cursor,pOciError, 1,OCI_FETCH_NEXT,OCI_DEFAULT)) == 0)
    printf("fetched id %d and name %s\n",id,ename);
    answer = OCIHandleFree(pOciError, OCI_HTYPE_ERROR);
    return 0;
    }

  • Cursors are not closed when using Ref Cursor Query in a report  ORA-01000

    Dear Experts
    Oracel database 11g,
    developer suite 10.1.2.0.2,
    application server 10.1.2.0.2,
    Windows xp platform
    For a long time, I'm hitting ORA-01000
    I have a 2 group report (master and detail) using Ref Cusor query, when this report is run, I found that it opens several cursors (should be only one cursor) for the detail query although it should not, I found that the number of these cursors is equal to the number of master records.
    Moreover, after the report is finished, these cursors are not closed, and they are increasing cumulatively each time I run the report, and finally the maximum number of open cursors is exceeded, and thus I get ORA-01000.
    I increased the open cursors parameter for the database to an unbeleivable value 30000, but of course it will be exceeded during the session because the cursors are increasing cumulatively.
    I Found that this problem is solved when using only one master Ref Cursor Query and create a breake group, the problem is solved also if we use SQL Query instead of Ref Query for the master and detail queries, but for some considerations, I should not use neither breake group nor SQL Query, I have to use REF Cursor queries.
    Is this an oracle bug , and how can I overcome ?
    Thanks
    Edited by: Mostafa Abolaynain on May 6, 2012 9:58 AM

    Thank you Inol for your answer, However
    Ref Cursor give me felxibility to control the query, for example see the following query :
    function QR_1RefCurDS return DEF_CURSORS.JOURHEAD_REFCUR is
    temp_JOURHEAD DEF_CURSORS.JOURHEAD_refcur;
              v_from_date DATE;
              v_to_date DATE;
              V_SERIAL_TYPE number;
    begin
    SELECT SERIAL_TYPE INTO V_SERIAL_TYPE
    FROM ACC_VOUCHER_TYPES
    where voucher_type='J'
    and IDENT_NO=:IDENT
    AND COMP_NO=TO_NUMBER(:COMPANY_NO);
         IF :no_date=1 then
                   IF V_SERIAL_TYPE =1 THEN     
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT
              AND ((TO_NUMBER(VOCH_NO)=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
              OR (TO_NUMBER(VOCH_NO) BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
              OR (TO_NUMBER(VOCH_NO)<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
              OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
                   ORDER BY TO_NUMBER(VOCH_NO);
                   ELSE
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT               
              AND ((VOCH_NO=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
              OR (VOCH_NO BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
              OR (VOCH_NO<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
              OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))     
                   ORDER BY VOCH_NO;          
                   END IF;
         ELSE
                   v_from_date:=to_DATE(:from_date);
                   v_to_date:=to_DATE(:to_date);                         
              IF V_SERIAL_TYPE =1 THEN
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
              AND IDENT=:IDENT                         
                   AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
                   OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
                   OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
                   OR (:from_date is null and :to_date is null ))     
                   ORDER BY VOCH_DATE,TO_NUMBER(VOCH_NO);     
              ELSE
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT                         
              AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
                   OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
                   OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
                   OR (:from_date is null and :to_date is null ))     
                   ORDER BY VOCH_DATE,VOCH_NO;          
              END IF;
         END IF;               
         return temp_JOURHEAD;
    end;

  • Unable to use ref cursor as a input parameter at the time of inserting reco

    Hi
    i am unable to use ref cursor when inserting the data to oracle 11g from visual studio 2008. please help me as early as possible my code is bellows
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Web.Configuration;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public partial class App_frmTest : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void btnClick_Click(object sender, EventArgs e)
    OracleCommand cmd=new OracleCommand();
    Data objdata = new Data();
    int i = 0;
    string constr = "Data Source=Cwc;User Id=scott; Password=tiger;";// enlist=false; pooling=false;
    OracleConnection con = new OracleConnection(constr);
    /*Connection Open*/
    con.Open();
    cmd.Connection = con;
    /*Connection Open End*/
    /*Select Through Ref Cursor*/
    cmd.CommandText = "scott.TEST_USER.getUSER";
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter p_rc = cmd.Parameters.Add("p_rc", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
    OracleParameter p_rc1;
    if (TextBox1.Text == "")
    p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, DBNull.Value, ParameterDirection.Input);
    else
    p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, Convert.ToInt16(TextBox1.Text), ParameterDirection.Input);
    // OracleParameter p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, 2, ParameterDirection.Input);
    OracleDataReader reader = cmd.ExecuteReader();
    DataSet ds = new DataSet();
    DataTable dt1 = new DataTable();
    dt1.Load(reader);
    ds.Tables.Add(dt1);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    cmd.Parameters.Clear();
    con.Close();
    con.Dispose();
    OracleCommand cmd1 = new OracleCommand();
    OracleConnection con1 = new OracleConnection(constr);
    con1.Open();
    cmd1.Connection = con1;
    cmd1.CommandText = "scott.TEST_USER.ADDUSER";
    cmd1.CommandType = CommandType.StoredProcedure;
    OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
    cmd1.ExecuteNonQuery(); // i am getting error when executing this line
    Server Error in '/CWC' Application.
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Source Error: 
    Line 77: OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
    Line 78: //OracleParameter P_MSG = cmd.Parameters.Add("P_MSG", OracleDbType.Varchar2, DBNull.Value, ParameterDirection.Output);
    Line 79: cmd1.ExecuteNonQuery();
    Line 80:
    Line 81: DataTable dt = new DataTable();
    Source File: d:\CWC\App\frmTest.aspx.cs    Line: 79 
    Stack Trace: 
    [AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
    Oracle.DataAccess.Client.OpsSql.ExecuteNonQuery(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr& opsDacCtx, IntPtr opsSubscrCtx, Int32& isSubscrRegistered, Int32 bchgNTFNExcludeRowidInfo, Int32 bQueryBasedNTFNRegistration, Int64& query_id, OpoSqlValCtx*& pOpoSqlValCtx, String pCommandText, IntPtr& pUTF8CommandText, IntPtr[] pOpoPrmValCtx, String[] ppOpoPrmRefCtx, OpoMetValCtx*& pOpoMetValCtx, Int32 prmCnt, Int32 bFromPool) +0
    Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() +4731
    App_frmTest.btnClick_Click(Object sender, EventArgs e) in d:\CWC\App\frmTest.aspx.cs:79
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Hi;
    Its better to ask it at visual studio forum site:http://social.msdn.microsoft.com/Forums/en-US/category/visualstudio
    Regard
    Helios

Maybe you are looking for

  • How to configure for music file loading

    I don't know if you can help with this one. If so, great. If not, I'm not insulted. I have a pair of Oakley Thumps, which are sunglasses with a built in MP3 player. I used to have little if any problem loading music on to them from my old windows bas

  • How to change field text at  run time in alv

    Hi all, Following are the columns need to displayed in an alv. year shd be the year which was entered in the selection screen. if the year entered was between 2001 and 2003 then the o/p(for year)  shd be as follows Division/Name     Position     Mana

  • Issue with Line Graph in SSRS

    I am pulling my hair our trying to format a line graph. Below is my current report -  The Line Graph I have created has a Category Group of "YearLogged" and "MonthLogged". The series I have added is an expression - =Count(IIF(Fields!InvoicePaid_.Valu

  • Key value pair like map or hashmap

    What is the alternative to java map or hashmap, which store key value paris, in Flex.

  • Facetime Beta issues

    I'm playing with FaceTime beta on my MacBook Pro and my iPhone 4. I've managed to get logged in but can't get a call to actually connect. That may be an issue with the Corporate LAN I'm on right now. My real question is this.... How do I add contacts