Manipulating result set in cursor

Hello,
BEGIN
FOR record IN ( SELECT empno, ename FROM emp
WHERE ROWNUM <= 1000 ORDER BY empno )
LOOP
-- How can I retrieve last 10 rows here in more productive way?
-- I have to scroll whole loop, or I can jupm directly to
990th row, or something else ?
END LOOP;
END;
Thank you a lot!

SET SERVEROUTPUT ON
DECLARE
  TYPE cursor_type IS REF CURSOR;
  cursor_name         cursor_type;
  TYPE record_type IS RECORD
    (empno            emp.empno%TYPE,
     ename            emp.ename%TYPE);
  rec                 record_type;
BEGIN
  OPEN cursor_name FOR
    'SELECT empno, ename
     FROM   (SELECT empno, ename,
                    RANK () OVER
                         (ORDER BY empno)
                         AS r
             FROM   emp)
     WHERE  r BETWEEN 991 AND 1000';
  LOOP
    FETCH cursor_name INTO rec;
    EXIT WHEN cursor_name%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE (rec.empno
    || ' '
    || rec.ename);
  END LOOP;
END;
-- or
SET SERVEROUTPUT ON
BEGIN
  FOR rec IN
    (SELECT empno, ename
     FROM   (SELECT empno, ename,
                    ROWNUM AS r
             FROM   (SELECT   empno, ename
                     FROM     emp
                     ORDER BY empno)
             WHERE  ROWNUM <= 1000)
     WHERE  r >= 991)
  LOOP
    DBMS_OUTPUT.PUT_LINE (rec.empno
    || ' '
    || rec.ename);
  END LOOP;
END;

Similar Messages

  • Random result set from cursor

    Hello all,
    I have a cursor defined that simply performs a SELECT. I would like to be able to dynamically state whether I'd like the entire result set returned or a random selection.
    The issue I'm having is that because the cursor is already defined I am trying to build this functionality into the LOOP. I am able to return random sets by using DBMS_RANDOM but I've only been able to do this when modifying the SELECT statement. I have considered an ORDER BY in the cursor and then simply EXIT'ing when the ROWNUM meets a certain number of returned results. This would, at least, provide the ability to return a user specified number of random records. Perhaps the ORDER BY could be modified by a cursor parameter?
    I'm hoping there's an elegant solution that I'm missing.
    Thanks for any help!
    Mark

    user10368702 wrote:
    Thanks for pointing out this feature to me. The problem is that my cursors are currently doing multi-table joins and the SAMPLE clause will not work with them. To clarify, I would like to programatically decide whether I'd like to return all the rows from the cursor, or just a sampling. The current method being used it to generate a random number and loop through the entire cursor until that rownum is found. I dislike the table walk, but am unable to come up with a way to return a specific sample size or record num. Ideally I'd like to be able to perform the equivalent of ROWNUM = X with the results from the cursor.
    Thanks for any help!Probably you can't use dynamic SQL (using OPEN or EXECUTE IMMEDIATE) for a particular reason? Because in that case you could just use your query as an inline view like that:
    SELECT * FROM (
    <YOUR_QUERY_INCLUDING DBMS_RANDOM_VALUE>
    WHERE <RANDOM_VALUE> <= <YOUR_LIMIT>and construct your query dynamically.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Sep 29, 2008 11:21 PM
    Removed unnecessary ORDER BY

  • Stored procedure that returns a cursor (result set)

    Hi,
    We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
    Any pointers please?
    Thanks

    Result set is of RowType and is not supported as a Stored Procedure as far as I know.
    HTH
    Sharma

  • Test Result set procedure with cursor

    i am really new for oracle and i don't know how to test my result set procedure in oracle.
    i am now working on Oracle 10g Express Edition.
    my procedure is below.
    create or replace procedure "GETORDERSBYCATALOGUECODE"
    (p_cataloguecode IN VARCHAR2, p_cursor IN OUT SYS_REFCURSOR )
    is
    begin
    open p_cursor for SELECT OrderID, NumberOrdered, CostCharged
    FROM OrderDetails
    WHERE CatalogueCode=p_cataloguecode;
    end;
    i am not sure how can i work with the the cursor and the procedure to display cursor data in Oracle 10g Express Web Admin?
    Tunk

    Hi, test the following statement in command line:
    SQL>VAR ordercursor REFCURSOR;
    SQL>EXECUTE GETORDERsBYCATALOGUECODE('001',:ordercursor);
    SQL>print :ordercursor;
    I+n your code, the error is OPEN ORDERCURSOR, the ORDERCURSOR cursor is open by default.+
    Your correct code  is:
    declare
    ordercursor SYS_REFCURSOR;
    orderid NUMBER;
    numberordered NUMBER;
    costcharged BINARY_DOUBLE;
    begin
    GETORDERsBYCATALOGUECODE('001',ordercursor);
    DBMS_OUTPUT.ENABLE(20000);
    DBMS_OUTPUT.PUT_LINE('Order Number, Number Ordered, Cost Charged');
    LOOP
    FETCH ordercursor INTO orderid, numberordered, costcharged;
    exit when ordercursor%notfound;
    DBMS_OUTPUT.PUT_LINE(orderid || ', ' || numberordered || ', ' || costcharged);
    END LOOP;
    CLOSE ordercursor;
    end;
    Roberto.
    Edited by: user584812 on Dec 23, 2008 3:47 PM

  • Result set without using cursor in Oracle

    Hi,
    I am very much new to oracle. we have a JDBC code and SQL Server procedure and which works fine. Now that we want to implement the same in Oracle also.we deceided not to change the JDBC but to change Stored Procedure and schema.
    Assume for Eg there is a stored procedure in SQL Server that return a simple query from table
    say
    creat procedure Test
    as
    begin
    select * from Accounts
    return
    end
    This procedure returns all the rows in the Accounts table and corresponding java code the fetch all the rows from ResultSet.
    CallableStatement cStmt = con.prepareCall("{ call test ? }" );
    cStmt.setInt( 1 , id_ );
    ResultSet rs = cStmt.executeQuery();
    while( rs.next() )
    // get all the rows
    will give all the rows from the table account.
    Now that we want to implement the same in Oracle.
    I just want to know, does Oracle provides any way to write a pl/sql or Procedure that returns resultset not as a cursor, but i should work with existing code.
    I don't want to declare like the below code
    CallableStatement cStmt = con.prepareCall("{? = call BrowseAccount.getRefCursor }");
    cStmt.registerOutParameter(1, OracleTypes.CURSOR);
    cStmt.execute();
    ResultSet rs = null;
    rs = (ResultSet)cStmt.getObject(1);
    while (rs.next() )
    // get the resultset
    If anybody have any suggestion or sample code will be really appreciated
    thanks
    vijay

    This is from the Oracle JDBC FAQ at http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_51_ :
    How do the JDBC drivers support Oracle REFCURSOR datatypes?
    The Oracle JDBC driver supports bind variables of type REFCURSOR. A REFCURSOR is represented by a JDBC ResultSet. Use the getCursor method of the CallableStatement to convert a REFCURSOR value returned by a PL/SQL block into a ResultSet. JDBC lets you call a stored procedure that executes a query and returns a results set. Cast the corresponding CallableStatement to oracle.jdbc.driver.OracleCallableStatement to use the getCursor method.
    Importing classes from the oracle.jdbc.driver package makes programs more readable. Here is a simple example. The samples subdirectory of the distribution has additional examples.
    import oracle.jdbc.driver.*;
    CallableStatement cstmt;
    ResultSet cursor;
    // Use a PL/SQL block to open the cursor
    cstmt = conn.prepareCall
    ("begin open ? for select ename from emp; end;");
    cstmt.registerOutParameter (1, OracleTypes.CURSOR);
    cstmt.execute ();
    cursor = ((OracleCallableStatement)cstmt).getCursor (1);
    // Use the cursor like a normal ResultSet
    while (cursor.next ())
    {System.out.println (cursor.getString (1));}

  • Is it possible to ref cursor(result set) as in parameter to procedure/funct

    Hi,
    I am getting a resultset/ref cursor from the Java side to the procedure/function as in parameter. Is this possible in oracle 10g.
    If yes can body send the links/suggestions describing some examples.
    Thanks,

    I am getting a resultset/ref cursor from the Java
    side to the procedure/function as in parameter. Is
    this possible in oracle 10g. It is possible, but it sounds like you have your application design entirely backwards.
    A ref cursor is designed to be used to pass a result set from a stored procedure to a client or calling application.
    So while you could use a screwdriver to hammer in a nail, you probably would not want to.

  • Generic cursors and generic result sets - How to?

    Hi all,
    I'm currently developing some kind of table export util. All it should do is to take a list of table names, determine the table structure (aka fields), fetch all data from this table and store a flat textfile containing all table data as ready-to-use INSERT statements.
    Please do not tell me that I could use DataPump or imp/exp, I know this but in this specific project this is not possible. I simply need one textfile per Table, that's it.
    So far my approach is the following:
    - Developed a package which contains a hard-coded list of tables as "TABLE OF VARCHAR2".
    - One procedure inside this package determines the list of fields for every passed tablename and their corresponding fieldtypes and generates a SELECT and INSERT query.
    - Another procedure will get the created SELECT query (which is valid, I've tested this) and performs a "OPEN <generic_cursor> FOR <select_query>";
    And here is also my problem. After "OPEN" the generic cursor I need a record to fetch the data row into. However as the list of tables is dynamic, so must be the records where to fetch into. I did not find any possible way of dynamically creating a record for the "FETCH INTO" statement. So far the only solution I've found was to hardcode the results of the tables and use IF/ELSE or CASE logic inside the data retrival procedure to fetch always into the right record:
    PROCEDURE DUMP_TABLES(P_TABLENAME VARCHAR2, P_SELECT VARCHAR2)
    G_CV genericcurtyp;
    T_MC_USERS MC_USERS%ROWTYPE;
    T_CDALBUM CDALBUM%ROWTYPE;
    BEGIN
    OPEN G_CV FOR P_SELECT;
    LOOP
    IF P_TABLENAME = 'MC_USERS' THEN
    FETCH G_CV INTO T_MC_USERS;
    ELSE
    FETCH G_CV INTO T_CDALBUM;
    END IF;
    EXIT WHEN G_CV%NOTFOUND;
    END LOOP;
    END;
    What I really would like to use is something like this:
    PROCEDURE DUMP_TABLES(P_TABLENAME VARCHAR2, P_SELECT VARCHAR2)
    G_CV genericcurtyp;
    TYPNAME VARCHAR2(32):='T_'||P_TABLENAME;
    MYRES TYPNAME%ROWTYPE;
    BEGIN
    OPEN G_CV FOR P_SELECT;
    LOOP
    FETCH G_CV INTO MYRES;
    EXIT WHEN G_CV%NOTFOUND;
    -- Do something with the row data in MYRES
    END LOOP;
    CLOSE G_CV;
    END;
    Of course I could hard-code everything, however I would like to keep the possibility to extend the list of tables simply by adding another entry to my list of tablenames without having to add additional code whenever the table list changes.
    I've tried also the "FOR i IN (<SELECT>)", however this won't accept a variable for the <SELECT>.
    Maybe someone here as an idea how to solve this problem without having to hard-code the required result sets of all affected tables? Or maybe I'm simply going the wrong way and someone could show me the right one?
    Any help would be appreciated.
    Best regards,
    Sascha

    You could use DBMS_SQL instead. DBMS_SQL provides DESCRIBE procedure so you can get count and datatypes of select list elements. If you are on 11g you can convert ref cursor to DBMS_SQL cursor or vice versa. But I would use a different solution. First of all, what are you creating "export" for? If you are planning to use it to load data into another Oracle database I'd simply use external tables. If you really need CSV, I'd use DBMS_SCHEDULER and run SQL*Plus task spooling output to a file.
    SY.

  • Just in time creation of Result Set

    I have this problem which is bugging me a lot. Actually I want to display some data on the browser by fetching it from the database. Now this result set could be quite big. So i would like to display on multiple pages like if there are 100 rows then 25 rows per page, so in total 4 pages. One way to do this load all data in memory and then display it moving your cursor down, but in this technique u have to keep large amount of data in memory. I want to fetch these rows as required like first time top 25 rows, next time next 25 rows and so on. I am stuck.. Please help me!!

    //you could use a Select bean:
    private com.ibm.ivj.db.uibeans.Select getSelectSQL() {
         if (ivjSelectSQL == null) {
              try {
                   ivjSelectSQL = new com.ibm.ivj.db.uibeans.Select();
                   ivjSelectSQL.setReadOnly(true);
                   ivjSelectSQL.setQuery(new com.ibm.ivj.db.uibeans.Query               ivjSelectSQL.setQuery(new com.ibm.ivj.db.uibeans.Query(getMyCon(), sqlGeneral()));
              } catch (java.lang.Throwable ivjExc) {
                   handleException(ivjExc);
         return ivjSelectSQL;
              ivjScrollPaneTableGen.setModel(getSelectSQL());
              ivjScrollPaneTableGen.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    ivjScrollPaneTableGen.setAutoCreateColumnsFromModel(true);
              getSelectSQL().execute();
    // after this your table will contain automatically all the rows.
    how the NextPage should work I haven't done yet, but I saw there is a setViewport(JViewport) function in JScrollPane class which seems to do the thing that you want.

  • Avoid JDBC sender error: Execute statement did not return a result set

    Hi!
    My JDBC sender adapter towards MS SQL server works fine, with an Execute statement calling a stored procedure that returns the source data needed. The stored procedure itself updates the status of database table records, so that only the unread records are returned each time the stored procedure is called.
    However, the communication channel monitoring sets a red flag for the JDBC sender adapter, when there are no values to fetch from the database table (using the stored procedure). Message says: "Database-level error reported by JDBC driver while executing statement 'EXECUTE FetchMessage 1, 9000'. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor."
    This is not an error situation, as I do not expect there to be any values to fetch from the database at all times.
    I do not see how to change the stored procedure to avoid this error.
    Is there a parameter to be set on the JDBC adapter that I can use, so the red flag is avoided?
    Thanks for any input!
    Regards,
    Oeystein Emhjellen

    Hi Oeystein Emhjellen.
    The problem is Store Procedure that has to generate always a ResultSet (or cursor). If it doesn't have a output, you have to generate an Empty ResultSet.
    Like a SELECT Statement:
    If there are data, SELECT get an output result but if it get nothing the SELECT Statement get a empty ResultSet.
    Ask to your database team.
    I hope it helps you.
    Bruno.

  • Problem in creating Saved Result Set (SRS) in OBIEE 10.1.3.4

    Hi,
    We have migrated Siebel Analytincs 7.8.5 to OBIEE 10.1.3.4, and we are now unable to create any SRS from OBIEE though we can create Segment and marketing cache for the segment.
    We did the following steps -
    1. Unisntall Siebel Analytincs 7.8.5
    2. Install OBIEE 10.1.3.4
    3. Use MIGRATE tool (sawmigrate) to migrate RPD & WEBCAT
    4. We have ALTERed the SRS tables - M_SR_HEADER, M_SR_ACCOUNT (as in OBIEE version there are many new columns have been added)
    5. We passed GLOBAL CONSISTENCY in the RPD
    6. We followed the steps in the document *"Oracle®Marketing Segmentation Guide Version 10.1.3.4 July 2008"*
    7. We created a Saved Result Set Format as instructed in the document - here we are very confused to select the list of columns - we don't know what should be the excat source / format
    8. Then we click the SRS create button
    9. We got the below error -
    Error Codes: QS2QOLYY:GDL67CY9:IHVF6OM7:OPR4ONWY:U9IM8TAC
    Error in getting cursor for WorkNode (Id:0)
    Authentication Failure.
    Odbc driver returned an error (SQLDriverConnectW).
    *State: 08004. Code: 10018. [NQODBC] [SQL_STATE: 08004] [nQSError: 10018] Access for the requested connection is refused. [nQSError: 43001] Authentication failed for Administrator in repository Star: invalid user/password. (08004)*
    Can anyone help us to resolve the issue ?
    A quick response is much much appreciated.
    Many Thanks,
    Prasanta

    Hi,
    It seems like you didnt setup the Administrator user for Saved Result Sets as it mentioned in the Marketing Segmentation Guide.
    Here is an extract from the guide:
    Setting Up the Web Administrator for Managing Cache and Saved Result Sets
    Some queries issued by the segmentation engine require the use of the Execute Physical stored
    procedure. These queries include delete statements on the cache, delete statements on the saved
    result sets, and insert statements for the cache and saved result set. The Execute Physical stored
    procedure must be run by a user with administrator privileges. The administrator user is set up in
    the instanceconfig.xml file.
    NOTE: The BI Administrator password and login parameters are case sensitive.
    To set up the administrative user in the instanceconfig.xml file
    1 Open a command shell and navigate to the <OracleBI>/web/bin, where <OracleBI> represents
    the root directory of the installation.
    2 Execute the following command:
    cryptotools credstore -add -infile <OracleBIData>/web/config/credentialstore.xml
    3 When prompted, enter the following values:
    Credential Alias: admin
    Username: Administrator
    Password: <enter Admin password here>
    Do you want to encrypt the password? y
    Passphrase for encryption: <password >
    Do you want to write the passphrase to the xml? n
    File "<OracleBIData>/web/config/credentialstore.xml" exists. Do you want to overwrite it? y
    4 Open the credentialstore.xml file and verify that the following section has been created:
    <sawcs:credential type="usernamePassword" alias=“admin">
    <sawcs:username> Administrator </sawcs:username>
    <sawcs:password>
    <xenc:EncryptedData>

  • The operation is not allowed for result set type FORWARD_ONLY

    Hi,
    I am trying to use scroll insensitive resultset in following manner-
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = stmt.executeQuery("some sql here");
    rs.last();
    but the rs.last() throws this exception-
    com.sap.dbtech.jdbc.exceptions.SQLExceptionSapDB: The operation is not allowed for result set type FORWARD_ONLY.
         at com.sap.dbtech.jdbc.ResultSetSapDB.assertNotForwardOnly(ResultSetSapDB.java:2725)
         at com.sap.dbtech.jdbc.ResultSetSapDB.last(ResultSetSapDB.java:557)
    Database version: Kernel    7.5.0    Build 019-121-082-363
    Driver Version: MaxDB JDBC Driver, MySQL MaxDB, 7.6.0    Build 030-000-005-567
    This used to work with 7.5 version driver. Why this is failing with 7.6 driver, any clues?
    Thanks,
    Vinod

    Hi Vinod,
    due to performance improvement when using forward only cursor we changed the default for the resultset type from TYPE_SCROLL_SENSITIVE to TYPE_FORWARD_ONLY starting with JDBC driver version 7.6. So I guess the exception comes from a statement where you didn't set the resultset type while creating it. Please check if all of the statements that you want to be scrollable have set the correct resultset type.
    Regards,
    Marco

  • Result Set fetch agonisingly slow

    I am having sporadic trouble retrieving data from a ResultSet. I do not know how to tell if it is an Oracle problem or a JDBC problem.
    In a while( results.next() ) loop, for some result sets it pauses for several seconds after every 10 iterations. This usually causes a webserver time-out and the results never get to the browser. It is NOT volume related, as some LARGER result sets from almost identical queries (i.e. with just one value in the where clause changed) run fine. We are using Oracle 8i, and the "problem" query always runs fine in SQLPlus (i.e. less than ten seconds for the execution and display of ~700 rows).
    some relevant evidence:
    a) Usually the PreparedStatement.execute() itself is pretty quick - just a few seconds at worst
    b) All result sets from this query pause every 10 iterations, but most pause for just a fraction of a second
    c) With a certain value in the where clause, the pauses are 4-30 seconds, which, even when only ~700 rows are returned, results in a response time of several minutes.
    d) The pauses are in the results.next() statement itself (I have output timestamps at the very beginning and the very end of the loop to show this).
    e) the query is a join of six tables
    f) the part of the where clause that changes is: AND FULFILLER.NAME IN (...) , where the IN clause can contain single or multiple names (but I am using a single value in the "problem" query)
    g) The FULFILLER.NAME column IS an indexed field, and that index IS being used (according to "EXPLAIN PLAN") in both the fast queries and the slow queries.
    What confuses me (amongst several things) is this: I would have thought that the values in the where clause would only affect the creation of the ResultSet, and not the reading of that result set. Am I wrong? Any ideas anyone?
    Thanks,
    Martin Reynolds (renozu)

    I am having sporadic trouble retrieving data from a
    ResultSet. I do not know how to tell if it is an
    Oracle problem or a JDBC problem.
    In a while( results.next() ) loop, for some
    result sets it pauses for several seconds after every
    10 iterations. This usually causes a webserver
    time-out and the results never get to the browser. It
    is NOT volume related, as some LARGER result sets from
    almost identical queries (i.e. with just one value in
    the where clause changed) run fine. We are using
    Oracle 8i, and the "problem" query always runs fine in
    SQLPlus (i.e. less than ten seconds for the execution
    and display of ~700 rows).
    some relevant evidence:
    a) Usually the PreparedStatement.execute() itself is
    pretty quick - just a few seconds at worst
    b) All result sets from this query pause every
    10 iterations, but most pause for just a fraction of a
    second
    c) With a certain value in the where clause, the
    pauses are 4-30 seconds, which, even when only ~700
    rows are returned, results in a response time of
    several minutes.
    d) The pauses are in the results.next() statement
    itself (I have output timestamps at the very beginning
    and the very end of the loop to show this).
    e) the query is a join of six tables
    f) the part of the where clause that changes is:
    AND FULFILLER.NAME IN (...) , where the IN
    clause can contain single or multiple names (but I am
    using a single value in the "problem" query)
    g) The FULFILLER.NAME column IS an indexed field, and
    that index IS being used (according to "EXPLAIN PLAN")
    in both the fast queries and the slow queries.
    What confuses me (amongst several things) is this: I
    would have thought that the values in the where clause
    would only affect the creation of the
    ResultSet, and not the reading of that result
    set. Am I wrong? Any ideas anyone?
    this honestly doesn't HAVE to be the case... depending on the cursor.
    i think if one has a forward only cursor the database could figure it out as it scans along the table. it should be fater in fact because if it does like this you only do one table scan and not two. this theory seems to fall apart when you say it is using the index BUT if I was writing a database and you had a forward only cursor AND the distribution of keys in the index indicated that there were many rows that would match your query I might ignore the index and do it as described.
    so call me crazy but here is my suggestion...
    if the cursor you are using is a forward only cursor then try a scrollable cursor.
    if it is already a scrollable cursor or changing it didn't help then try this...
    rs.last();
    rs.beforeFirst();
    // now process normally using next()i would think that this would force the database to find all the rows.... so it should help.
    also the server timeout issue will sort of need to be addressed also if the query still takes a long time to run...
    Thanks,
    Martin Reynolds (renozu)

  • Calling stored procedure returning result set

    Hi all,
    i know this issue is discussed quite often. I did not find an answer in the forums, not in the manual and even not in the examples for stored procedure.
    So i try it here once more :)
    Description:
    GET_SKS:
    The GET_SKS procedure is used to generate a number of surrogate keys. It has one input parameter NUM_SKS_IN that specifies the number of keys to generate. The generated keys are returned as a result set.
    So i tried:
    CallableStatemant sproc_stmt = lsession.connection().prepareCall("{ call Get_SKS(?,?)}");
    sproc_stmt.setInt(2,1);
    sproc_stmt.registerOutParameter(1,OracleTypes.CURSOR);
    sproc_stmt.execute();
    ResultSet sproc_result = (ResultSet) sproc_stmt.getObject(1);
    I got the exception:
    java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GET_SKS'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Thanks for help! This is really getting frustrating...
    Regards,
    ak

    Hi there,
    i could speak to our one of our admins. This is what he gave me:
    CREATE OR REPLACE PROCEDURE "TCSDBOWNER"."GET_SKS"
       (num_sks_in IN INTEGER,
        sk_out OUT SYS_INFO.SYS_INFO_SK%TYPE)
    AS
    /*+
    || Procedure - GET_SKS - Oracle
    ||
    || Description:
    ||   This procedure is used to get one or more primary keys for tables with
    ||   surrogate keys as the primary key.  This number is unique across all
    ||   tables and installations for a given client.
    ||
    || Parameters:
    ||   num_sks_in - INTEGER: number of surrogate keys to return
    ||   sk_out - sk_subtype: first key in the sequence of requested keys
    ||
    || History:
    ||   08/30/01,dcs: Created
      CURSOR request_cur IS
        select DBMS_LOCK.REQUEST(170333184) from dual;
      CURSOR release_cur IS
        select DBMS_LOCK.RELEASE(170333184) from dual;
      CURSOR dual_sk_cur IS
         select SEQ_SK.NEXTVAL SK
           from DUAL;
      v_base_offset SYS_INFO.BASE_OFFSET%TYPE;
      v_sk SYS_INFO.SYS_INFO_SK%TYPE;
      v_sqlstring VARCHAR2(1000);
      v_cursor_handle INTEGER;
      v_return INTEGER;
    BEGIN
      IF num_sks_in < 1 THEN
        TCS_EXC.RAISE_ERROR(TCS_EXC.num_sks_in_lt_1);
      END IF;
      OPEN request_cur;
      FETCH request_cur INTO v_return;
      CLOSE request_cur;
      IF v_return <> 0 AND v_return <> 4 THEN
        TCS_EXC.RAISE_ERROR(TCS_EXC.sk_gen_lock_failed);
      END IF;
      v_cursor_handle := DBMS_SQL.OPEN_CURSOR;
      v_sqlstring := 'ALTER SEQUENCE SEQ_SK INCREMENT BY '|| TO_CHAR(num_sks_in);
      DBMS_SQL.PARSE(v_cursor_handle, v_sqlstring, DBMS_SQL.V7);
      v_return := DBMS_SQL.EXECUTE(v_cursor_handle);
      DBMS_SQL.CLOSE_CURSOR(v_cursor_handle);
      GET_BASE_OFFSET(v_base_offset);
      OPEN dual_sk_cur;
      FETCH dual_sk_cur INTO v_sk;
      CLOSE dual_sk_cur;
      sk_out := (v_base_offset * 10000000000) + v_sk - num_sks_in + 1;
      v_cursor_handle := DBMS_SQL.OPEN_CURSOR;
      v_sqlstring := 'ALTER SEQUENCE SEQ_SK INCREMENT BY 1';
      DBMS_SQL.PARSE(v_cursor_handle, v_sqlstring, DBMS_SQL.V7);
      v_return := DBMS_SQL.EXECUTE(v_cursor_handle);
      DBMS_SQL.CLOSE_CURSOR(v_cursor_handle);
      OPEN release_cur;
      FETCH release_cur INTO v_return;
      CLOSE release_cur;
      IF v_return <> 0 THEN
        TCS_EXC.RAISE_ERROR(TCS_EXC.sk_gen_lock_failed);
      END IF;
    END GET_SKS; Ok, i tried with that but even not succeded yet. Can anybody help me to code that into a java call?
    Regards,
    ak

  • Result Set

    Using JDBC i am calling a Stored Procedure. Where is the resulting result set kept (in server side or client side). Please provide details

    Using JDBC i am calling a Stored Procedure. Where is
    the resulting result set kept (in server side or
    client side). Please provide detailswhether you create a ResultSet from a statement, a prepared statement or a callable statement (Stored Procedure) is not relevant to your question.
    this question is a bit tricky to answer because a lot will depend on the implementation by the various database vendor but here is how it works more or less.
    a query is executed on the server let's say "SELECT a,b,c, FROM MyTable WHERE d=1;"
    the database finds 6 rows in the table that match the where clause.
    at this point the database server maintains a cursor (pointer to the 6 matching rows) and the client gets an implementation of the ResultSet API to work with. in this case the client physically has the implementation of the ResultSet interface but the data is on the server.
    when methods like next() are called the appropiate row(s) are fetched from the server using the maintained cursor.
    generally i think you can say that unless you are talking about the actual class the result set doesn't really "exist" but really is made up of meta-data and pointers to the right places to find the data.
    so having said all that i'm not sure why it matters to you. why should you care where the data really is?

  • Result Set returned iteration.Please advise

    I am invoking a Stored Function from my Java code that returns back
    a result set.
    I have put a break point on my code.
    The value of the rs = OracleResultSetImpl(id=59)
    and when the cursor reaches while(rs.next()),it does not go in this loop
    and exits out.
    Does this mean that there are no records returned back ?
    But then the rs should be null instead of showing :OracleResultSetImpl(id=59)
    public synchronized ResultSet getAcctChgData(String OrderNo) throws SQLException {
               CallableStatement loadAcctChgStatement=null;
             ResultSet rs=null;
             try
                  loadAcctChgStatement = con.prepareCall("{call ? := SF_ACCOUNTCHG(?)}"); //This is oracle function
                  loadAcctChgStatement.registerOutParameter(1,OracleTypes.CURSOR);
                  loadAcctChgStatement.setString(2,OrderNo);
                  loadAcctChgStatement.execute();
                  rs = (ResultSet)loadAcctChgStatement.getObject(1);
                  while(rs.next()){
                       String f_OrderID  = rs.getString("FixOrderID");
                       String f_EffTs    = rs.getString("EffTs");
                       String f_ClrAcct  = rs.getString("ClrAcct");     
             }catch (SQLException e){
              logger.error("No record found for Order No " + OrderNo);
             return rs;
         }

    Yes, and I'm suprised you don't get a classCastException, actually. I'd've expected you to get a return code through the output parameter.

Maybe you are looking for

  • ~ POWER PC APPLICATIONS NO LONGER SUPPORTED ~

    Hello there I am running on Mac OS X  v 10.8.2 I have a licenced copy of MS Office and have not had a problem using it, until a recent Mac 'update'! Since then, whenever I try to access it I get the following message: "You can't open the application

  • Indent each paragrath in the text

    Hello guys, Can you help me out? I am creating a program that read from text file A and write to text file B with each new paragraph indented 3 spaces. import java.io.*;           public class Paragraphs {           // create two File Streams        

  • Can't uninstall Desktop Manager 5.0.1.

    Hello, I'm trying to uninstall the DM v5.0.1 on my Windows 7 machine. Following the usual uninstall procedure (remove programs on the control panel), I get an error stating that "This action is only valid for products that are currently installed'. H

  • HT1725 I purchased two CD's on Sunday and both have problems with jumping tracks.   How can I redownload?

    I purchased two CD's and both have problems with some of songs jumping tracks.     It does this on my computer and on the Ipod.     How can I redownload the purchases?

  • Flash Catalyst (especially Paninni) Rules - This Is An Apology

    Hi… Two weeks ago I posted a question asking how to create a horizontal scrollbar that reveals content from both the right and left sides of a page. I became frustrated because I couldn't bring Catalyst in line with the design I had created in Illust