Extending a Cursor (for stored procedure)

(Embedded image moved to file: PIC19643.PCX) Dan Christopher @ SUNLIFE
03-13-97 04:39 PM
I receive the following message when I try to extend a cursor for an
execute of a stored procedure. I believe my problem has to do with using
ODBC as my driver (to attach to a MS-SQL Server 6.5 database) , but does
anyone have any other insight to what my problem may be.
SYSTEM ERROR: Invalid state transition from FETCH to EXTENDED for statement of
type qqdb_OdbcCursor.
Class: qqdb_UsageException with ReasonCode: DB_ER_INVALIDSTATE
Error #: [801, 152]
Detected at: qqdb_Statement::ValidTransition
Last TOOL statement: method w_connect.ExecStoredProc, line 53
Error Time: Thu Mar 13 13:55:59
Exception occurred (remotely) on partition "Dan_Connect_CL0_Part1",
(partitionId = 210EC99B-811A-11D0-8D72-82F2A190AA77:0x22f:0x20, taskId =
[210EC99B-811A-11D0-8D72-82F2A190AA77:0x23d:0x3.25]) in application
"Forte
Runtime", pid 314 on node 543SZAD in environment dusgroup.
Here is a example of my code.
constant NUM_ROWS_FETCH = 2; //default to fetch 50 rows
//at a time.
l_inputDataSet :DBDataSet = new; //input parameters for
Forte
l_statementtype :integer;
l_return :integer; //return value for
open/extend
//cursor functions
l_numRows :integer; //the number of rows fetch
l_DBStatement :DBStatementHandle; //statement handle for
sp
l_statementtype = DB_CV_EXECUTE ;
l_DBStatement = p_dbsession.Prepare(
commandString = p_exec,
inputDataSet = l_inputdataset,
cmdType = l_statementtype);
// fill in the parameter values
for i in 1 to p_parameters.items do
//integer parameter
if (p_parameters.GetParmIndicator() = 'I') then
l_inputdataset.SetValue(position = i,
Value = p_parameters[i].GetParmValue().integervalue);
else
l_inputdataset.SetValue(position = i,
Value = p_parameters[i].GetParmValue());
end if;
end for;
//open the cursor
l_return = p_dbsession.OpenCursor(
StatementHandle = l_DBStatement,
inputDataSet = l_inputdataset,
resultDataSet = p_outputdataset);
// Continue to Fetch and Extend the Cursor untill all rows have been
retrieved.
while (l_return != DB_RS_NONE) do
l_numRows = p_dbsession.FetchCursor(
StatementHandle = l_DBStatement,
resultDataSet = p_outputdataset,
maxRows = NUM_ROWS_FETCH);
if (l_numRows = NUM_ROWS_FETCH) then //extend the cursor
l_return = p_dbsession.ExtendCursor(
StatementHandle = l_DBStatement,
resultDataSet = p_outputdataset);
else
exit;
end if;
end while;
//close the cursor
p_dbsession.CloseCursor(statementHandle = l_DBStateMent);
return l_numRows;

Hi Dan,
Thanks for the Calrification on Cursors, We solved it here.
As for your Extend problem goes the Fetch should go outside the while
loop I think.
You first fetch and then get the next data set in a loop. I feel
that this should solve your problem.
Thankx
Bala
[email protected]
Sage Solutions
353 Sacramento
Suite 1360
San Francisco
CA 94111.

Similar Messages

  • Ref cursors for stored procedure

    Hi every body,
    I am new one,I am in learning stage.
    My java developer was ask me give set of results.
    i am using in my code sys_refcursor, my questions are.
    SQL> create or replace procedure sysref(p_out out sys_refcursor) is
    2 begin
    3 open p_out for select empno,ename from employee;
    4 end;
    5 /
    I am using the procedure like above procedure.
    1) How to use ref cursors in procedure. what is the main use.
    2) How to close ref cursors in procedure.If it is need.
    3) How to use exceptions in procedures for ref cursors.
    Give me one example with complete structure.
    Please help me
    new one
    Edited by: subba on Aug 19, 2010 12:08 AM
    Edited by: subba on Aug 19, 2010 12:09 AM

    subba wrote:
    1) How to use ref cursors in procedure. what is the main use.All SQL in Oracle are parsed as cursors in the Shared Pool. The client code (be that PL/SQL or Visual Basic or Java) gets a handle or reference to this SQL cursor on the server.
    Using this handle, the client can fetch rows using the cursor (the cursor is like a program - the executable binary version of the source SQL code).
    Clients implement their interfaces with this SQL cursor handle in different ways. PL/SQL alone supports:
    - implicit cursor handles
    - explicit cursor handles
    - DBMS_SQL cursor handles
    - reference cursor handles
    Why so many? Different tools for different jobs. Each has its pros and cons and each is suited for specific (and different) types of problems.
    A ref cursor is special in that PL/SQL can pass this SQL cursor reference handle to an external client to use - like Java.
    Why?
    The basic concept is that of abstraction. Removing the complexities of SQL and the database design and SQL optimisation from the Java code. Instead, Java calls a PL/SQL proc. This proc creates the SQL cursor, and uses a reference cursor variable to store the SQL cursor handle. It can then pass this to Java. This means that the entire SQL is encapsulated in the PL/SQL proc. We can now modify it, optimise it, support data models changes in the database via the PL/SQL proc... all without even having to recompile the Java code that makes the call and consumes the ref cursor the PL/SQL proc gives it.
    2) How to close ref cursors in procedure.If it is need.Yes. A very important factor - well spotted.
    As PL/SQL can pass ref cursors to external clients. it does not automatically close these cursors. It does not know when the client has consumed the cursor. It will only close it when the cursor is still open, when the Oracle server session is terminated.
    So it is important that the client (Java in this case) closes the cursor when done. If not, the cursor will remain open, will continue to occupy server resources... and if the client opens more and more of these cursors, the server process will run out of resources.
    Cursor leakage by Java developers are common - and can simply be avoided by closing the cursor once the Java code has consumed it.
    3) How to use exceptions in procedures for ref cursors.No. Why? Why would you want to deal with the exception in a PL/SQL proc? The Java code wants to open that cursor. It knows why. It knows what to do when that cursor fails or is empty. It interacts with the user. How is the PL./SQL proc, whose only function is to construct the SQL and pass the cursor handle to Java, to know any of this?
    Exceptions in this regard should typically be handled in Java. Not in PL/SQL.
    Of course, if that PL/SQL proc has parameters, it also needs to validate these and it needs to raise application exceptions to inform the Java caller when these parameters are invalid.
    But actually catching exception in this case... does not make much sense. As what can the PL/SQL do about the error when it is a "server" and Java is the "client"?
    It is like saying that the Oracle Server should handle all exceptions when TOAD is used and incorrect SQL is passed to it. How does it make sense for Oracle to process SQL errors and the TOAD client not getting any results from a wrong SQL and not knowing that there was even an error with that SQL?

  • Importing function with multiple ref cursors in Stored Procedure of Oracle 12c database Using EF6

    Hi Good day!
    I can able to import function for stored procedure of oracle db and able to add the complex type and get the output but i tried to import the procedure which having two ref cursors and unable to retrieve the column information. Only able to retrieve the
    columns of first ref cursor.  Please help me to get the result of two ref cursors which acting as out parameters.

    Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
    The link may point you in the right direction.
    http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram

  • Returning SQL cursor from Stored Procedure

    Hi,
    I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
    I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
    assume both query returns equal number of rows.. however both are not related to each other..

    RP wrote:
    Hi,
    I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
    I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
    assume both query returns equal number of rows.. however both are not related to each other..It sounds like what you need is a ref cursor.
    First thing to remember though is that cursors do not hold any data (see: {thread:id=886365})
    In it's simplest form you would be creating a procedure along these lines...
    SQL> create or replace procedure get_data(p_sql in varchar2, p_rc out sys_refcursor) is
      2  begin
      3    open p_rc for p_sql;
      4  end;
      5  /
    Procedure created.
    SQL> var rc refcursor;
    SQL> exec get_data('select empno, ename, deptno from emp', :rc);
    PL/SQL procedure successfully completed.
    SQL> print rc;
         EMPNO ENAME          DEPTNO
          7369 SMITH              20
          7499 ALLEN              30
          7521 WARD               30
          7566 JONES              20
          7654 MARTIN             30
          7698 BLAKE              30
          7782 CLARK              10
          7788 SCOTT              20
          7839 KING               10
          7844 TURNER             30
          7876 ADAMS              20
          7900 JAMES              30
          7902 FORD               20
          7934 MILLER             10
    14 rows selected.
    SQL> exec get_data('select deptno, dname from dept', :rc);
    PL/SQL procedure successfully completed.
    SQL> print rc
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
            40 OPERATIONS
            50 IT SUPPORTWhich takes an SQL statement (as you said that both your queries were unrelated), and returns a ref cursor, and then your Java code would fetch the data using that cursor.
    Now, as for getting your rows to columns and combining two queries that do that... something along these lines...
    SQL> select * from x;
    C
    A
    B
    C
    SQL> select * from y;
    C
    D
    E
    F
    SQL> ed
    Wrote file afiedt.buf
      1  select x.col1, x.col2, x.col3
      2        ,y.col1 as col4
      3        ,y.col2 as col5
      4        ,y.col3 as col6
      5  from (
      6        select max(decode(rn,1,col1)) as col1
      7              ,max(decode(rn,2,col1)) as col2
      8              ,max(decode(rn,3,col1)) as col3
      9        from (select col1, rownum rn from (select * from x order by col1))
    10       ) x
    11  cross join
    12       (
    13        select max(decode(rn,1,col1)) as col1
    14              ,max(decode(rn,2,col1)) as col2
    15              ,max(decode(rn,3,col1)) as col3
    16        from (select col1, rownum rn from (select * from y order by col1))
    17*      ) y
    SQL> /
    C C C C C C
    A B C D E F... will do what you ask. For further information about turning rows to columns read the FAQ: {message:id=9360005}

  • How to check performance for Stored procedure or Package.

    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.

    user13483989 wrote:
    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.Oracle has provided set of Tools to monitor the Performance.
    Profilers being one of them; If you wish to understand more on PL/SQL Optimization, please read PL/SQL Optimization and Tuning.
    See example of DBMS_PROFILER.
    See example of PLSQL Hierarchial Profiler

  • Structure for Stored Procedure Call

    Hi All,
             Guys I am trying to call a stored procedure call using receiver jdbc adapter...
    This is the outgoing message:
    <b><?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:SP_DB xmlns:ns0="urn:sce-com:xi:dev:mohammf">
    - <Test>
    - <PP_TEST_P action="EXECUTE">
      <table>PP_TEST_P</table>
      <RECTYPEIND type="CHAR">CC</RECTYPEIND>
      <JENUMBER type="CHAR">76724</JENUMBER>
      <COMPANY type="CHAR">BCEO</COMPANY>
      <CONSTANT1 type="CHAR">AB</CONSTANT1>
      <SYSTEMDATE type="CHAR">08/12/2007</SYSTEMDATE>
      <DR_CR_ID type="CHAR">0</DR_CR_ID>
      <AMOUNT type="CHAR">934928599475843</AMOUNT>
      <MONTH_NUMBER type="CHAR">000008</MONTH_NUMBER>
      <COST_CENTER type="CHAR">LosAngeles</COST_CENTER>
      <ORDERNO type="CHAR">694950375830</ORDERNO>
      <WBS type="CHAR">Southern California Edis</WBS>
      <ACCOUNTID type="CHAR">6949503758</ACCOUNTID>
      <BATCH_ID type="CHAR">3408102007</BATCH_ID>
      <ASSIGNMENT type="CHAR">Technology Solutio</ASSIGNMENT>
      <GL_JOURNAL_CATEGORY type="CHAR">GHTF</GL_JOURNAL_CATEGORY>
      <PROFIT_CENTER type="CHAR">3434694950</PROFIT_CENTER>
      <REFDOCNUMBER type="CHAR">00000000004304300056006056</REFDOCNUMBER>
      </PP_TEST_P>
    - <PP_TEST_P action="EXECUTE">
      <table>PP_TEST_P</table>
      <RECTYPEIND type="CHAR">XX</RECTYPEIND>
      <JENUMBER type="CHAR">76724</JENUMBER>
      <COMPANY type="CHAR">BCEO</COMPANY>
      <CONSTANT1 type="CHAR">AB</CONSTANT1>
      <SYSTEMDATE type="CHAR">08/12/2007</SYSTEMDATE>
      <DR_CR_ID type="CHAR">0</DR_CR_ID>
      <AMOUNT type="CHAR">934928599475843</AMOUNT>
      <MONTH_NUMBER type="CHAR">000008</MONTH_NUMBER>
      <COST_CENTER type="CHAR">LosAngeles</COST_CENTER>
      <ORDERNO type="CHAR">694950375830</ORDERNO>
      <WBS type="CHAR">Southern California Edis</WBS>
      <ACCOUNTID type="CHAR">6949503758</ACCOUNTID>
      <BATCH_ID type="CHAR">3408102007</BATCH_ID>
      <ASSIGNMENT type="CHAR">Technology Solutio</ASSIGNMENT>
      <GL_JOURNAL_CATEGORY type="CHAR">GHTF</GL_JOURNAL_CATEGORY>
      <PROFIT_CENTER type="CHAR">3434694950</PROFIT_CENTER>
      <REFDOCNUMBER type="CHAR">00000000004304300056006056</REFDOCNUMBER>
      </PP_TEST_P>
      </Test>
      </ns0:SP_DB></b>
    The error I am getting is: 
    <b><i>2007-08-20 09:44:05 Error Unable to execute statement for table or stored procedure. 'PP_TEST_P' (Structure 'Test') due to java.sql.SQLException: ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !)
    2007-08-20 09:44:05 Error JDBC message processing failed; reason Error processing request in sax parser: Error when executing statement for table/stored proc. 'PP_TEST_P' (structure 'Test'): java.sql.SQLException: ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !)
    2007-08-20 09:44:05 Error MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'PP_TEST_P' (structure 'Test'): java.sql.SQLException: ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !)
    2007-08-20 09:44:05 Error Exception caught by adapter framework: null
    2007-08-20 09:44:05 Error Delivery of the message to the application using connection JDBC_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'PP_TEST_P' (structure 'Test'): java.sql.SQLException: ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !).</i></b>
    Pls advice..
    XIer
    Message was edited by:
            XIer

    Hi,
    Check your DATA TYPE attributes with the attributes of the column names in the Database table.  There is a mismatch between the DT and Table in the database.
    <b>Cheers,
    *RAJ*</b>

  • ALDSP 3.0 -- schema owner for stored procedure or SQL Statement

    Using ALDSP, I have a need to create a physical service based on a stored procedure or a SQL statement. I am wondering what will happen when I move to another deployment environment where the schema owner changes. In our QA and Prod environments, we have a different schema owner for all tables in the application (the DBAs believe this prevents unwanted updates to a prod environment). DSP elegantly supports this for normal table- and view-based physical services by mapping schemas through the DSP console after deployment. Will I get the same type of mapping capability for stored procedures and SQL statements? I noticed that I can add a SQL-based function to a physical service...is there a way to pass in the physical table name from that data service to the procedure or SQL statement?
    Thanks,
    Jeff

    Schema name substitution should work for stored procedures just like it does for tables. If it doesn't - report a bug.
    You don't get any help for sql-statement based data services - dsp doesn't parse the sql provided. One thing you could do is use the default schema (following the user of your connection pool), and not specify the schema in your sql-statement.

  • Too many arguments for stored procedure call

    I have a stored procedure with 34 arguments, including the return value. I am trying to call it from java using JDBC thin drivers (jdk11, oracle815), but I get the "wrong number or types of arguments" error message. JDBC-OCI fails also. I saw a reference in this discussion group to there being a limit of 32 arguments for stored procedure calls from jdbc (posted 6/29/99). Is there such a limit? If so, is there a fix or workaround? If there is not a limit, how can I determine which argument is causing the problem?
    Many thanks.
    Mike
    java.sql.SQLException: ORA-06550: line 1, column 13:
    PLS-00306: wrong number or types of arguments in call to 'PUT_CHECK'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.jav
    a)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement
    .java)
    at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
    nt.java)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepar
    edStatement.java)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStat
    ement.java)
    at metris.quickcheck.database.DS1.main(DS1.java:79)
    null

    I must confess I still don't understand your problem. By rows ...
    I have an sql that recodes a column and has 1450 rows. This doesn't work
    although when I use the same with less rows 40-60 it works.... do you mean rows in the table or elements in the CASE() statement ?
    From the 9i SQL Reference:
    " The maximum number of arguments in a CASE expression is 255, and each WHEN ... THEN pair counts as two arguments. To avoid exceeding the limit of 128 choices, you can nest CASE expressions. That is return_expr can itself be a CASE expression."
    According to the 10g docs the limit is the same there.
    Cheers, APC

  • How to use @prompt for stored procedure in universe

    Hi,
    I am using Bo XI R3.1 and universe was built on stored procedures and database is sql server 2005.
    I would like to show the list of values for prompts in report which they are based on parameters given for stored procedures in universe. Instead of typing the value for prompts the user should select some values for the prompt.
    I've tried in the universe putting the prompt syntax but didn't work could any one please let me know how this will be achived
    Thanks in advance,
    Eswar

    Hi Eswar,
    Please try the following steps mentioned below:
    1. Go to Insert -> click Tables and Import the table which needs to assign LOVu2019s into Universe panel.
    Objects which are created on tables may appear in inactive mode.
    2. Right click on the stored procedure -> Click on Edit stored procedures.
    3. Click on the Browse universe objects from Stored Procedure Editor. (Button avaial on the left)
    4. Select the object which you want to assign for the List of values.
    5. Enter the desired text which you want to display in the WebI reports in the Edit prompt Label.
    6. Export the Universe.
    Before doing the above steps:
    While creating for SP Univ, a parameter screen appears after selecting SP. In the "Value" field enter a dummy value and
    from the "Next Execution" drop down at the right select "Prompt me for a value".
    Regards,
    Rohit

  • Toplink support for stored procedure with 2 OUT  REF CURSOR ?

    Can Toplink StoredProcedureCall be used with Oracle PLSql procedure with 2 OUT parameters. Parameter type is Ref Cursor (Oracle PLSQL resulset)
    Regards

    In a TopLink StoredProcedureCall using an OUT CURSOR the cursor is assumed to map to the result set for the TopLink query.
    For example if you had a stored procedure READ_ALL_EMP that returned a out cursor of EMP rows, you could use that procedure in a TopLink mapped Employee class mapped to the EMP table and use the stored procedure in a ReadAllQuery for the Employee class.
    If the procedure does not return data that maps to objects, you can use a DataReadQuery to access the data. The out cursor would be returned as a Vector of DatabaseRows that contain the data from the cursor rows.
    If the procedures data is complex and does not map to objects, it may be better to access the procedure directly through JDBC.

  • Cursor in stored procedure fails

    Hi,
    In our application we have a stored procedure which is called with in parameters to generate data into some table. This procedure is being called from another procedure.
    This procedure has been used to generate data into the table without any problem since oracle 9i. Last year we have upgraded to oracle 11g after that this procedure is failing intermittently to generate data. When this procedure is executed 50 times it fails atleast once to generate data. If we rerun the procedure for the failed case it generates the data without any change to program code nor any change in underlying data. It doesn't fail if we rerun. Therefore we are unable to simulate the problem.
    Procedure has got a very simple code.
    proc1 (p1 date,p2 date) is
    begin
    for c1_rec in c1 (select col1,col2
    from x,y where x.......)
    loop
    end loop;
    end;
    First we thought for some reason this procedure was not executed at all. But it is not the case. Actually it calls the procedure but the cursor inside the procedure doesn't fetch any records. Also it doesn't report any oracle error.
    Appreciate if any one can help me in this.
    Thanks & Regards,
    Raja

    vaidyanathanraja wrote:
    4. If there is a logical error, the same procedure should not generate data when it is rerun. Behaviour should be the same at all times.Incorrect. Something like NLS settings for example can make the same code, behave differently. E.g. a date string is passed and implicitly converted to a date. And this will work for most dates from different session using different NLS settings (e.g. yyyy/mm/dd versus yyyy/dd/mm). And these sessions will provide different results using the same parameters calling the same application code.
    There are a number of such run-time factors that influences code.
    5. Failed means it didn't generate the expected output. Which means that there is a problem with that SQL being executed the way it is, with the parameters used. You need to isolate the problem further.
    6. Parameter values are right.Have you proved that by using a test case that runs the very same SQL via a test proc, using the same parameter, via a job? Ran that test case interactively via sqlplus?
    You need to pop the hood and isolate the problem.
    7. I came across one blog saying different behaviour for REF CURSOR between oracle 10g and 11g and he says it is oracle bug. I don't know whether it is applicable for this case also.Bahumbug. There are many Oracle bugs. As there is in all software. However, you have not provided any evidence of a bug.
    Application code is behaving inconsistently. That is the symptom. Oracle system code is not relevant until you can prove that the inconsistency is not in the application code, but lower down the call stack.

  • Cursor in stored procedure

    Hi,
    1. I am using a cursor XYZ to store some data into a variable @abc and then using this variable as one of the conditions in filling a #TEMP_TABLE in my STORE_PROC procedure. The #TEMP_TABLE does not get populated.
    It works fine when I create a temp table and run the same query outside of the stored procedure.
    Here is a sample:
    DECLARE CURSOR XYZ FOR
    SELECT DISTINCT column-name
    FROM database name..Table Name
    WHERE condition
    OPEN XYZ
    FETCH XYZ INTO @abc
    IF (@@sqlstatus = 2)
    BEGIN
    ........returns an error code
    END
    WHILE(@@sqlstatus = 0)
    BEGIN
    INSERT INTO #TEMP_TABLE
    SELECT
    FROM
    WHERE
    AND .............. = @abc
    END
    Please facilitate a solution as to how to get this to work in a stored procedure?
    Thank you,
    Developer.

    Seems you question is concerned with MS SQL Server syntax. Here is
    the Oracle forum. Nevertheless all you are doing can be completed
    using the single sql statement:
    INSERT INTO <<temp table>>
    SELECT ... FROM ...
    WHERE ...
    AND ... IN (SELECT UNIQUE column-name
    FROM database name..Table Name
    WHERE condition)
    Rgds.

  • Scrollable Cursor in Stored Procedure

    I am trying to implement a scrollable cursor that exists in a stored procedure. Here is my situation:
    o Oracle 9i (9.2.0.1.0) for both client and server.
    o OCI Interface in purely C++ environment
    o I am able to compile/link program with 9i client library, and successfully fetch data from a stored proc that contains a nonscrollable/forward only/traditional cursor without any problems.
    I have a stored proc that looks like this:
    procedure test(
    testcursor out cv_types.cv_fit_data
    ) as
    begin
    open testcursor
    for select data_id,
    text
    from data;
    end test;
    This is where I run into problems:
    First I allocate an OCIStmt handle and bind it to the proc. Then using the stmt handle that points to the proc, I bind a secondary handle that points to the cursor (testcursor above) by calling OCIBindByPos with type=SQLT_REF (See OCI ref manual on binding ref cursor). Next, I execute the proc via OCIStmtExecute with the mode=OCI_STMT_SCROLLABLE_READONLY using the statement handle that points to the procedure. Then I use that secondary stmt handle to fetch the rows via OCIStmtFetch2(). I am able to fetch the rows if I stick to OCI_FETCH_NEXT, but when I attempt to use any scrollable features such as OCI_FETCH_ABSOLUTE, it bails with an ORA-24391 error. Upon further investigation, I found out that this error occurs when the stmt is not executed with mode=OCI_STMT_SCROLLABLE_READONLY. The clincher is that I did execute in that mode... Has anyone been faced with a similar situation? Am I tackling this the wrong way? Any help, even pointers to any docs I missed on the subject, is greatly appreciated.
    Thanks,
    Bryan
    I am using OCI in C++ to fetch the data via OCIStmtFetch2(...) method.

    vaidyanathanraja wrote:
    4. If there is a logical error, the same procedure should not generate data when it is rerun. Behaviour should be the same at all times.Incorrect. Something like NLS settings for example can make the same code, behave differently. E.g. a date string is passed and implicitly converted to a date. And this will work for most dates from different session using different NLS settings (e.g. yyyy/mm/dd versus yyyy/dd/mm). And these sessions will provide different results using the same parameters calling the same application code.
    There are a number of such run-time factors that influences code.
    5. Failed means it didn't generate the expected output. Which means that there is a problem with that SQL being executed the way it is, with the parameters used. You need to isolate the problem further.
    6. Parameter values are right.Have you proved that by using a test case that runs the very same SQL via a test proc, using the same parameter, via a job? Ran that test case interactively via sqlplus?
    You need to pop the hood and isolate the problem.
    7. I came across one blog saying different behaviour for REF CURSOR between oracle 10g and 11g and he says it is oracle bug. I don't know whether it is applicable for this case also.Bahumbug. There are many Oracle bugs. As there is in all software. However, you have not provided any evidence of a bug.
    Application code is behaving inconsistently. That is the symptom. Oracle system code is not relevant until you can prove that the inconsistency is not in the application code, but lower down the call stack.

  • OCI8: returning cursors from stored procedures

    The short version of my question is:
    In OCI8, how do open a cursor from the database stored procedure, return it to my C++ program and fetch from it, given that in OCI8 cursors and cursor functions are becoming obsoleted?
    The long version of the same question is:
    I am converting my C++ code from the Oracle 7.3 OCI driver to the Oracle8 OCI driver. One thing I did very frequently in Oracle 7.3 OCI code is open a multi-row select cursor within a stored procedure and return that cursor to my program. In the program, I would then do the fetching with the returned cursor. This was very useful, as it allows me to change the queries in the stored procedure (for example, to append information to certain columns or make some data in all uppercase) without recompiling the application due to a changed SQL string.
    My 7.3 psuedocode is as follows:
    stored procedure def:
    TYPE refCurTyp IS REF CURSOR;
    FUNCTION LoadEmployeeData RETURN refCurTyp;
    stored procedure body:
    FUNCTION LoadEmployeeData RETURN refCurTyp IS
    aCur refCurTyp;
    BEGIN
    OPEN aCur FOR
    SELECT emp_id, emp_name
    FROM employee_table
    ORDER BY emp_name;
    return aCur;
    END;
    OCI code: // all functions are simplified, not actual parameter listing
    // declare main cursor variable #1 and return cursor variable #2
    Cda_Def m_CDAstmt, m_CDAfunction;
    // open both cursors
    oopen(m_CDAstmt, ...);
    oopen(m_CDAfunction, ...);
    // bind cursor variable to cursor #2
    oparse(&m_CDAstmt, "BEGIN :CUR := MYPACKAGE.LoadEmployeeData; END;");
    obindps(&m_CDAstmt, SQLT_CUR, ":CUR", &m_CDAfunction);
    // run cursor #1
    oexn(&m_CDAstmt);
    // bind variables from cursor #2, and fetch
    odefineps(&m_CDAfunction, 1, SQLT_INT, &m_iEmpId);
    odefineps(&m_CDAfunction, 2, SQLT_CHAR, &m_pEmpName);
    while (!ofen(&m_CDAfunction))
    // loop: do something with fetch
    // values placed in m_iEmpID and m_pEmpName
    This works perfectly, and has really helped to make my code more maintainable. Problem is, in Oracle 8 OCI both cursors and the cursor functions (such as oopen()) are becoming obsoleted. Now it uses statement and environment handles. I know I can still use Cda_Def and cursors--for a while--within OCI8, but I need to know the official up-to-date method of returning a cursor from the database and fetching within my C++ code. Any code fragment, or explanation of what I need to do in OCI8 would be appreciated (perhaps I need to bind to a statement handle instead? But the stored procedure still returns a cursor.)
    The Oracle8 OCI has a new SQLT_ type, SQLT_RSET, which the header file defines as "result set type". Unfortunately, it's almost completely undocumented in the official documentation. Am I supposed to use this instead of the obsolete SQLT_CUR?
    Thanks,
    Glen Mazza

    Email me diorectly and I will get you some code that might help. I fail to see the relevance of posting this type of information in the JDeveloper forum.

  • Explain plan/autotrace for stored procedure

    Hello,
    I have an stored procedure executing a select statement. I would like to use autotrace or explain plan or something to check how my select statement is executed.
    So far I've only accomplished to use autotrace on statements i write in sql*plus. The problem here is that my select statement uses some user defined types (lists of numbers and dates). Also if possible I would like my application to call the procedure providing the parameters. I feel kind of lost here.
    My query is something like this:
    int_list list_of_numbers;
    int_list2 list_of_numbers;
    date_list list_of_dates;
    select * from table1, table(int_list) i1, table(int_list2) i2, table(date_list) d1 where ....

    No, i do not have a "close cursor" procedure, but I just leave the tracing on for now. When in production I will turn it off.
    This is just a test system so I have full control over everything.
    Yes, I granted execute on dbms_session and alter session to my user, because I received an error when trying to execute the stored procedure. But with dbms_support and monitor I can't even compile my stored procedure.
    I granted execute on dbms_monitor to my user and the procedure compiled fine! When trying to grant execute on dbms_support sql*plus complained on not even finding that package/procedure/whatever.
    Thank you for all your help!

Maybe you are looking for