Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:12:26+00:00 2026-06-14T20:12:26+00:00

Possible Duplicate: Oracle Accessing updated records during the same transaction I have an Oracle

  • 0

Possible Duplicate:
Oracle Accessing updated records during the same transaction

I have an Oracle stored procedure somewhat like this (actual sqls are different)

CREATE OR REPLACE PROCEDURE mysp
IS
v_copied_row table%ROWTYPE ;

 CURSOR p_copied_rows IS
 select *
 from table ;

BEGIN
  delete from table
where <some condition>

OPEN p_copied_rows ;
LOOP
FETCH p_copied_rows into v_copied_rows ;
<do something with fetched row>
END LOOP
close p_copied_rows;
END;

Ideally, I am expecting that the deleted rows should not be part of the result set I am fetching from the cursor, but those are.

I am new to oracle, and want to understand if i am doing something wrong here?

P.S. I’ve to use cursor for some complex things, so replacing cursor with the SQL is not an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:12:27+00:00Added an answer on June 14, 2026 at 8:12 pm

    If your actual code matched the code you posted, the rows you you delete would not be returned by the cursor

    If I create a table with 100 rows

    SQL> ed
    Wrote file afiedt.buf
    
      1  create table foo
      2  as
      3  select level col1
      4    from dual
      5* connect by level <= 100
    SQL> /
    
    Table created.
    

    and then create a PL/SQL block that replicates what you posted which deletes 98 of the rows, the cursor that is opened will return only 2 rows

    SQL> select count(*) from foo;
    
      COUNT(*)
    ----------
           100
    
    SQL> declare
      2    cursor non_deleted_rows
      3        is select *
      4             from foo;
      5    l_rec foo%rowtype;
      6  begin
      7    delete from foo
      8     where col1 <= 98;
      9
     10    open non_deleted_rows;
     11    loop
     12      fetch non_deleted_rows into l_rec;
     13      exit when non_deleted_rows%notfound;
     14
     15      dbms_output.put_line( l_rec.col1 );
     16    end loop;
     17  end;
     18  /
    99
    100
    
    PL/SQL procedure successfully completed.
    

    Now, if you open the cursor before you issue the DELETE, the cursor will return the rows that were deleted. Perhaps in your actual code, the OPEN statement is before the DELETE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: A good reference for Oracle PL/SQL I need make a procedure to
Possible Duplicate: How to best split csv strings in oracle 9i I have some
Possible Duplicate: oracle PL/SQL: sort rows I run this query: Select a.product, sum( case
Possible Duplicate: Oracle DB: How can I write query ignoring case? I have an
Possible Duplicate: SELECT INTO using Oracle I have one table in my oracle database.
Possible Duplicate: how to convert csv to table in oracle I have a query
Possible Duplicate: Convert Unixtime to Datetime SQL (Oracle) We have a table of type
Possible Duplicate: Oracle RAC and sequences I have a Oracle RAC configured in my
Possible Duplicate: Why does Oracle 9i treat an empty string as NULL? I have
Possible Duplicate: Oracle table change monitor This is the question that is asked to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.