As promised in the My SQL Cursors and Loops article, this article explores the use of cursors and their role in stored procedure programming.A cursor is a special kind of loop for traversing through an SQL resultset one row at a time.I have a different set of recommendations about cursor FOR loops, which I learned from one of my mentors in the PL/SQL world, Bryn Llewellyn, Oracle’s PL/SQL product manager.Let’s take a closer look at these five cursor FOR loop recommendations. This advice may come as something of a shock to you.statements might credit one bank account and debit another.
You can manipulate Oracle data flexibly and safely because PL/SQL fully supports all SQL data manipulation statements (except ), transaction control statements, functions, pseudocolumns, and operators.Cursor declarations must appear after variable and condition declarations but before handler declarations.Also keep in mind that the cursor SELECT statement cannot have an INTO clause; it's strictly read-only.CREATE TABLE My Table (Id INT Identity, Col2 int, Col3 int) INSERT INTO My Table (Col2, Col3) VALUES (2,1), (3,0), (4,0),(5,0),(6,0) SELECT * from My Table WHILE (SELECT COUNT(*) FROM My Table WHERE Col3=0) @Hemant Sisodia you can replace the conditional in the WHILE to an EXISTS which should be quicker as it short circuits. If you need to be to REALLY fast you can use your PK to loop through those records too, i.e.only work on PK values between 1-10,000 for first loop, then do the next 10k etc.At the end of a transaction that makes database changes, Oracle makes all the changes permanent or undoes them all.If your program fails in the middle of a transaction, Oracle detects the error and rolls back the transaction, restoring the database to its former state.