OPEN CURSOR FOR  DELETE ROWS

This transaction will work properly?
I know it work but I have feeling it may cause a problem
To open a cursor and delete the row I have selected.
CREATE OR REPLACE PROCEDURE PRC_MAIN_INTER IS
BEGIN
BEGIN
FOR A IN (SELECT B.HIST_ID
FROM MOBIDEO.MAIN_INTER B
WHERE B.STATUS = 9)
LOOP
BEGIN
DELETE MAIN_INTER C WHERE C.HIST_ID = A.HIST_ID;
COMMIT;
END LOOP;
END;
COMMIT;
END PRC_MAIN_INTERF;

Sagi wrote:
Toon Koppelaars wrote:
Why not just:
BEGIN
DELETE FROM MOBIDEO.MAIN_INTER B WHERE B.STATUS = 9;
COMMIT;
END;
The original transaction is longer I have truncate it .
It also use log HIST_ID and some more detail for log table .Question: Are mobideo.main_inter and main_inter the same table? If so then
declare
  cursor c_main_inter is select hist_id from main_inter where status=9 for update;
begin
  for c in c_main_inter
  loop
    -- Logging, any other processing, etc.
    delete from main_inter where current of c_main_inter;
  end loop;
  commit;
end;

Similar Messages

  • What is the keyboard shortcut for "delete row" in a table?

    What is the keyboard shortcut for "delete row" in a table within a pages document?

    Click on the row number to select the entire row. Right-click, and select Delete Row from the menu. There is no keyboard shortcut.

  • Open cursor for ...using...

    Hi all
    1 general question- can someone explain me how 'using keyword in 'open cursor for ...' statement works.
    Does it replace where clause and how?
    open cur_xx for qry_xxx using text_xxx
    where 'text_xxx' is going to be my codition in select statement
    Tahnks everyone

    http://oraclesvca2.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems35.htm

  • Better approach for deleting rows using trigger or procedure

    Hi,
    Please suggest which option is better for deleting rows from table trigger or procedure and why?
    In datawarehousing and OLTP DB's.
    Edited by: user6040008 on Nov 2, 2012 4:51 AM

    Hi,
    Please suggest which option is better for deleting rows from table trigger or procedure and why?
    In datawarehousing and OLTP DB's.
    Edited by: user6040008 on Nov 2, 2012 4:51 AM

  • OPEN cursor for large query

    OPEN cursor
    When you OPEN a cursor for a mult-row query, is there a straightforward way that you can have it only retrieve a limited number of rows at a time and then automatically delete those rows as you do the FETCH against them? I'm thinking of setting up multiple sequential cursors, and opening and closing them as the rows are processed. But I'm hoping there might be a better way.
    The problem is that I'm running out of TEMPORARY during the OPEN cursor stage.
    The application I am working on needs to work in Standard Edition and Personal Edition versions of Oracle.
    Thank you.

    Thanks - I had read the documentation before, but interpreted it differently.
    What I had read was in:
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i45288
    The extract of interest was:
    Opening a Cursor
    Opening the cursor executes the query and identifies the result set, which consists of all rows that meet the query search criteria. For cursors declared using the FOR UPDATE clause, the OPEN statement also locks those rows. An example of the OPEN statement follows:
    DECLARE
    CURSOR c1 IS SELECT employee_id, last_name, job_id, salary FROM employees
    WHERE salary > 2000;
    BEGIN
    OPEN C1;
    Rows in the result set are retrieved by the FETCH statement, not when the OPEN statement is executed.
    My interpretation was that the result of the query was put into the temporary tablespace and then retrieved into the program during the FETCH.
    Assuming I was wrong, what I'm wondering now is how I can possibly be running out of temporary space during this OPEN cursor process.

  • Open Cursor for insert actually inserts

    Have been using code similar to this to prepare an SQL insert
    statement before entering a loop to perform the inserts. Find
    that the open actually performs an insert when it is executed,
    so the table always has an extra row of garbage.
    Is there some way to stop this behaviour? ProC compiler option
    or open parameter. Currently I am doing a ROLLBACK after the
    open to clear it.
    Using the prepare because the table name is not known at compile
    time.
    EXEC SQL AT DB_1 PREPARE insert_cust FROM :szSqlInsertCustomer;
    EXEC SQL AT DB_1 DECLARE insert_cust_cursor CURSOR FOR insert_cust;
    EXEC SQL AT DB_1 OPEN insert_cust_cursor USING :customerId;
    for ( ....)
    customerID = ...;
    EXEC SQL AT DB_DCMS EXECUTE insert_cust;
    Also tried passing in the tablename as a host variable
    EXEC SQL INSERT INTO :szTableName (CUSTOMER_ID) VALUES (:customerId);
    ProC compiler gives the following error:
    INSERT INTO :szTableName (CUSTOMER_ID) VALUES (:customerId);
    ........................1
    PCC-S-02201, Encountered the symbol ":" when expecting one of the following:
    ( an identifier, a quoted string, date, table, count,
    extract, interval, multiset, the, time, timestamp, treat,
    trim, avg, max, min, sum, stddev, variance,
    Thanks

    You don't DECLARE and OPEN an insert statement (just selects). Just use EXECUTE ... USING ...

  • Open cursor for string and select from partition (cannot bind)

    Hi,
    i don't manage to use a bind variable for a select ... from ... PARTITION(...).
    It doesn't work to use something like
    open cur for 'select ... from ... PARTITION(:1) where ...' using 'NDAY_20120301';So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    Doesn't that prevent from re-use in library_cache?
    best regards,
    Frank

    >
    So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    >
    Yes it does.
    Doesn't that prevent from re-use in library_cache?
    >
    Yes it does.
    So why do you care? Unless you have large numbers of partitions what difference does it make? Bind variables are useful to keep Oracle from doing hard parses of queries that are basically the same but use different filter values. Such as an INSERT statement that uses different values FOR EACH ROW rather
    You are just constructing the main (non-filter) part of the query one time and need a single value for the entire query regardless of how many rows - that isn't really a use case for bind variables and isn't going to provide any real benefit.
    So the real question is why do you even care about something that wouldn't provide any benefit to you even if you could do it?
    Looks like you just want to 'roll your own' parallel processing rather that use, and pay for, Oracle's parallel functionality.
    If each partition uses its own tablespace you could filter on the FILE Id of the ROWIDs since the file number will be different for each tablespace and datafile.
    1. Determine the list of file numbers for each partitions tablespace.
    2. Use a WHERE DBMS_ROWID.ROWID_RELATIVE_FNO (ROWID) = :n filter (or use IN (:n1, :n2))to filter rows based on file number(s) for the partition you want
    See DBMS_ROWID.ROWID_RELATIVE_FNO in the PL/SQL Packages and Types doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_rowid.htm#i1004259

  • PL/SQL procedure for deleting rows

    We have to delete rows from a table by initiating parallel processes depending on no of connections, and also variable commit frequency. The procedure has to start by itself in case of failure of 1 or more parallel processes, by identifying the position where it stopped. Please some one help me what would be th elogic needed to write the [rocedure.
    Thanks in Advance
    Edited by: 864979 on Jun 9, 2011 10:02 PM

    Be careful of how this is designed and coded. It is very easy to do it horribly wrong, causing contention and problems.
    Have a look at DBMS_PARALLE_EXECUTE.
    If the package is not available on your Oracle version, then look at {message:id=1534900} for a manual approach.

  • Open cursor for a dynamic query

    Hi,
    I'm using forms6i and db 10g
    I want to create a procedure like below
         PROCEDURE pop_cursor (generic_cur IN OUT gencurtyp, querystring varchar2) IS
         BEGIN
              OPEN generic_cur FOR querystring;
         END;where generic_cur is a Ref Cursor and querystring will contain a query statement like 'select col1... from table1'
    The above way i'm not able to do that, i'm getting error
    Encountered the symbol 'QUERYSTRING' when expecting on of the following:
    select
    Is there any alternative??
    Please help

    You can only use that sort of dynamic sql in the database. maybe you can return the ref cursor to the form from a db-function, i don't know if it works in forms 6i.
    But you could tell us your requirement, maybe you can implement it without these dynamic things.

  • Open cursor for internal table

    Hi folks,
    I have a tricky question concerning the cursor function and internal tables. First of all, it is not possible to create a view. Instead I've to use a function module for extracting some data to the BI system.
    Actually most of the time I work with SELECT (for outer joins) and internal tables. At the end I have a internal table and must open an cursor. As fact, I can't open a cursor for an internal table - only database tables are allowed.
    OPEN CURSOR WITH HOLD s_cursor FOR SELECT * FROM lt_temp.
    Does someone have a clue how to solve my problem? Obviously I have to use a db table for a open cursor statement but on the same way I have to use a internal table for all my previous SELECT-statements.
    Thanks in advance for your help.
    Regards,
    Mrcl

    Why don't you use EXEC and ENDEXEC
    Check this link
    http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3b8b358411d1829f0000e829fbfe/content.htm

  • Open cursor for and bind variables

    Hello all,
    how can I assign values to a bind variable before opening a cursor?
    example code:
    DECLARE
       TYPE ref_cur_t IS REF CURSOR;
       l_ref_cur   ref_cur_t;
       l_query VARCHAR2 (100)
             := 'select * from table t1 where ndx= :var_index' ;
    BEGIN
       -- assign a value to :var_index
       OPEN l_ref_cur FOR l_query;
    END;Thanks!

    Something like this ->
    scott@ORCL>
    scott@ORCL>DECLARE
      2     l_ref_cur   sys_refcursor;
      3     l_query VARCHAR2 (100) := 'select * from emp where empno = :var_index';
      4     l_empno  number(4);
      5  BEGIN
      6     l_empno := &emno;
      7     -- assign a value to :var_index
      8     OPEN l_ref_cur FOR l_query using l_empno;
      9  END;
    10  /
    Enter value for emno: 7698
    old   6:    l_empno := &emno;
    new   6:    l_empno := 7698;
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:19.78
    scott@ORCL>Regards.
    Satyaki De.

  • Open cursor for existing procedure

    Is it possible to open a refcursor for an existing procedure as apposed to opening a refcursor for a standard select statement. For example:
    Standard select:
    OPEN refcursor FOR
    select * from my_table;
    RETURN the_cursor;
    Based on an existing procedure:
    OPEN refcursor FOR
    my_package.my_procedure();
    RETURN the_cursor;
    Note: my_procedure returns a table of record type rows defined by myself in the package spec.
    Any help is much appreciated
    Regards
    Tony

    Hi Sven
    Thank you for that information however I am still a little unsure as to how to call the procedure including the necessary parameters. The procedure in question has the following IN parameters with one OUT parameter.
    my_procedure (p_context_id in number,
    p_username in varchar2,
    p_mdata out mtab)
    As you stated, if it is a procedure, which it is, then use the following:
    my_package.my_procedure(the_cursor);
    However if I need to pass parameters in the call that kind of conflicts where 'the_cursor' is?
    Any ideas?
    Tony

  • Open cursor for PLSQL table of records

    Is it possible to open a cursor for all data in a PLSQL table of records?
    something like
    cursor c (p1 number) is select * from <plsqltab>
    where <plsqltab>.col = p1

    There is no such thing as a PL/SQL table. Yes, I know that many calls this structure in PL/SQL a table. And that is exactly where all this confusion stems from.. and trying to treat such a "table" as an Oracle table using SQL.
    The correct terms are dynamic array (indexed by integer) or dynamic associative array (indexed by varchar). And an array is nothing like a table ito RDBMS processing.
    Yes, you can run SQLs against arrays. But it is "expensive". Why? Because the data sits inside PL/SQL Engine. Not in the SQL Engine. The data is in a PL/SQL defined structure. Not a SQL defined structure.
    So.. the data needs to be shipped from the PL/SQL Engine to the SQL Engine and converted into a format that the SQL Engine can understand and use.
    Also, once shipped and converted the SQL structure is not indexed. Which means that the only option is a full table scan of that structure.
    So you need to ask yourself why do you want to use SQL against a PL/SQL array? As soon as you do that, you are saying "Hey, this PL/SQL table ain't good enough and I need to process it using SQL".
    So why then does that data sit inside a PL/SQL array and not in a SQL table?
    Oracle provides you with the ability to create temporary session tables. These can be indexed. SQL can be run against them without all the "expenses" that are associated with running SQL against a PL/SQL array.
    PL/SQL arrays is a great tool. But only when it is the right tool to use. When someone says he/she needs SQL to use this tool, then I question the choice of the tool. Make sure you use the right tool for the job.

  • Open cursor for dynamic sql

    Hi
    I am using oracle 8.1.7 on solaris.
    I have created
    SQL> CREATE OR REPLACE PACKAGE TEST_PKG AS
    2 TYPE row_cursor IS REF CURSOR RETURN TEMP_TAB%ROWTYPE;
    3 PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor);
    4 END TEST_PKG;
    5 /
    Package created.
    now i am trying to create the procedure Return_Columns_proc by
    CREATE OR REPLACE PACKAGE BODY TEST_PKG AS
    PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor) AS
    QUERY_STR VARCHAR2(850);
    x number ;
    BEGIN
    x:=1;
    QUERY_STR :='SELECT * FROM temp_tab where order_line_id = '||x;
    OPEN c_return FOR QUERY_STR;
    END Return_Columns_proc;
    END TEST_PKG;
    I am getting following error.
    SQL> show error
    Errors for PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    8/4 PL/SQL: Statement ignored
    8/9 PLS-00455: cursor 'C_RETURN' cannot be used in dynamic SQL OPEN
    statement
    any help for this error.

    The error says it all. You have defined a strong ref cursor and it cannot be used with dynamic sql. However, that does not mean you cannot use the query directly in the OPEN clause
    OPEN c_Return FOR SELECT * FROM temp_tab where order_line_id = X ;

  • Open cursor for a nested table

    Hi,
    I want to open a cursor like:
    open c1 for select * from emp;
    BUT
    I what the cursor results to be populated with contents of a nested table or associative array..
    How can this be done???
    Thanks in advance,
    teo

    Well, given a variable YOUR_EMP of nested table type EMP_NT it could be as simple as
    open c1 for select * from TABLE( CAST(your_emp AS emp_nt));Cheers, APC

Maybe you are looking for

  • Model Execute Exception in a WD Callable Object

    Hello, I've been having some trouble making queries to a database through a Web Dynpro Development Component (GP Interface). I imported a Web Service and the calls are being made through there. I know that the Web Service works just fine as I've test

  • Help with several errors

    Hi Masters I'm creating a scenario like which describes in: /people/community.user/blog/2006/10/24/exposing-bapi-as-web-services-through-sap-xi I have created in SLD: 1 Products, 1 Software Component, 1 Technical System and 1 Bussines System. I have

  • ERROR consistency check in  recordset structure validation

    Hi, I have a file that has the format below. The file is managed with the below content conversion parameters. However, it's not working and the error message that i get is "Conversion of file content to XML failed at position 0: java.lang.Exception:

  • Cartesian selects after Update from 10.0.2.0.3 to 10.0.2.0.5

    Hello, we just installed the patch 10.0.2.0.5 on a 10.0.2.0.3 database and some selects didn't work as before. While changing the select clause, there are diffent counts. There are 3 tables: Detail_1 => MASTER_1 <= Detail_2 MASTER_1 has a primary and

  • "Are you sure you want to open 10 messages?" warning

    When I highlight >10 messages to open at once, I get a warning to the effect of "Are you sure you want to open ## messages?" This is annoying, because I obviously highlighted >10 messages, and of course I want to open them all at once. My question is