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.
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:
DECLARE TYPE myRecType IS RECORD ( [COLUMN NAME] [DATA TYPE], . .. );
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:
Declare cursor Mycursor is SELECT ColA, ColB, Colc FROM MyTable; Begin -- Iterate using a for loop for X in Mycursor loop --print Mycursor.ColA -- do whatever you want to do with your data end loop; end;