I am a new to Pl/sql and I need to learn to write simple pl/sql scripts. Is there any difference between cursors and records in PL/sql? So far I find them both similar.

  • Ok after a bit of research I have figured it out. Cursors are just memory created By SQL when a DML statement is fired. You could have implicit or explicit cursors. Where as records are datatypes holding data of different kinds. – Null Pointer Mar 24 '14 at 20:14

new to PL SQL here, and wanted to help with what i know...

A record is similar to a table row, can hold one value for each column at a time. cursors are like "tables" they may hold multiple rows (records if you will).

this is one way how you can declare a record:

TYPE myRecType

Cursors can be explicit or implicit. Implicit cursors are created each time you run a query, and have some attributes that may give you an idea of what happened after your query is ran. e.g.

SQL%FOUND will return either TRUE or FALSE if your DML statement affects at least 1 record.

SQL%ROWCOUNT will return the number of rows afected by your DML statement...

Explicit cursors on the other hand, are needed for advanced data manipulation, you can create your own cursor by supplying a query, and you can iterate through that cursor to do more data manipulations

simple syntax to declare a cursor with a SELECT query and loop through the results:

  cursor Mycursor is 
    FROM MyTable;

   -- Iterate using a for loop
  for X in Mycursor loop
    --print Mycursor.ColA
    -- do whatever you want to do with your data
  end loop;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.