A cursor is a temporary work area created in the system memory when a SQL statement is executed. A cursor contains information on a select statement and the rows of data accessed by it. This temporary work area is used to store the data retrieved from the database, and manipulate this data. A cursor can hold more than one row, but can process only one row at a time. The set of rows the cursor holds is called the active set.
In SQL procedures, a cursor make it possible to define a result set (a set of data rows) and perform complex logic on a row by row basis. By using the same mechanics, an SQL procedure can also define a result set and return it directly to the caller of the SQL procedure or to a client application.
A cursor can be viewed as a pointer to one row in a set of rows. The cursor can only reference one row at a time, but can move to other rows of the result set as needed.
To use cursors in SQL procedures, you need to do the following:
Declare a cursor that defines a result set.
Open the cursor to establish the result set.
Fetch the data into local variables as needed from the cursor, one row at a time.
Close the cursor when done
To work with cursors you must use the following SQL statements:
DECLARE CURSOR
OPEN
FETCH
CLOSE
There are two types of cursors in PL/SQL:
Implicit cursors:
These are created by default when DML statements like, INSERT, UPDATE, and DELETE statements are executed. They are also created when a SELECT statement that returns just one row is executed.
Explicit cursors:
They must be created when you are executing a SELECT statement that returns more than one row. Even though the cursor stores multiple records, only one record can be processed at a time, which is called as current row. When you fetch a row the current row position moves to next row.
Both implicit and explicit cursors have the same functionality, but they differ in the way they are accessed.
When you execute DML statements like DELETE, INSERT, UPDATE and SELECT statements, implicit statements are created to process these statements.
Oracle provides few attributes called as implicit cursor attributes to check the status of DML operations. The cursor attributes available are %FOUND, %NOTFOUND, %ROWCOUNT, and %ISOPEN.
For example, When you execute INSERT, UPDATE, or DELETE statements the cursor attributes tell us whether any rows are affected and how many have been affected.
When a SELECT... INTO statement is executed in a PL/SQL Block, implicit cursor attributes can be used to find out whether any row has been returned by the SELECT statement. PL/SQL returns an error when no data is selected.
The status of the cursor for each of these attributes are defined below :-
- %FOUND :
The return value is TRUE, if the DML statements like INSERT, DELETE and UPDATE affect at least one row and if SELECT ….INTO statement return at least one row.
The return value is FALSE, if DML statements like INSERT, DELETE and UPDATE do not affect row and if SELECT….INTO statement do not return a row.
example : SQL%FOUND
- %NOTFOUND :
The return value is FALSE, if DML statements like INSERT, DELETE and UPDATE at least one row and if SELECT ….INTO statement return at least one row.
The return value is TRUE, if a DML statement like INSERT, DELETE and UPDATE do not affect even one row and if SELECT ….INTO statement does not return a row.
example: SQL%NOTFOUND
- %ROWCOUNT :
Return the number of rows affected by the DML operations INSERT, DELETE, UPDATE, SELECT
example : SQL%ROWCOUNT
For Example: Consider the PL/SQL Block that uses implicit cursor attributes as shown below:
DECLARE var_rows number(5);
BEGIN
UPDATE employee
SET salary = salary + 1000;
IF SQL%NOTFOUND THEN
dbms_output.put_line('None of the salaries where updated');
ELSIF SQL%FOUND THEN
var_rows := SQL%ROWCOUNT;
dbms_output.put_line('Salaries for ' || var_rows || 'employees are updated');
END IF;
END;
In the above PL/SQL Block, the salaries of all the employees in the ‘employee’ table are updated. If none of the employee’s salary are updated we get a message 'None of the salaries where updated'. Else we get a message like for example, 'Salaries for 1000 employees are updated' if there are 1000 rows in ‘employee’ table.
Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
ReplyDeleteAndroid App Development Company
iOS App Development Company
Really Good tips and advises you have just shared. Thank you so much for taking the time to share such a piece of nice information. Looking forward for more views and ideas, Keep up the good work! Visit here for Product Engineering Services | Product Engineering Solutions.
ReplyDeleteyurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
M2C
Hollanda yurtdışı kargo
ReplyDeleteİrlanda yurtdışı kargo
İspanya yurtdışı kargo
İtalya yurtdışı kargo
Letonya yurtdışı kargo
FC2NU1
Portekiz yurtdışı kargo
ReplyDeleteRomanya yurtdışı kargo
Slovakya yurtdışı kargo
Slovenya yurtdışı kargo
İngiltere yurtdışı kargo
HGOGİ
Yunanistan yurtdışı kargo
ReplyDeleteAfganistan yurtdışı kargo
Amerika Birleşik Devletleri yurtdışı kargo
Amerika Samoası yurtdışı kargo
Angola yurtdışı kargo
J8M0O
Kocaeli
ReplyDeleteDenizli
Bartın
Kocaeli
Adana
OFT08K
bingöl
ReplyDeleteelazığ
hakkari
sakarya
erzincan
YAY3İ
elazığ
ReplyDeletegümüşhane
kilis
siirt
sakarya
JQ1E
elazığ
ReplyDeleteerzincan
bayburt
tunceli
sakarya
44YVUG
whatsapp görüntülü show
ReplyDeleteücretli.show
SAO
görüntülü.show
ReplyDeletewhatsapp ücretli show
WDBUP
Mersin Lojistik
ReplyDeleteAmasya Lojistik
Kayseri Lojistik
Kırklareli Lojistik
Erzurum Lojistik
LUPD
uşak evden eve nakliyat
ReplyDeletebalıkesir evden eve nakliyat
tokat evden eve nakliyat
kayseri evden eve nakliyat
denizli evden eve nakliyat
FYYJİ
9C68A
ReplyDeleteBayburt Evden Eve Nakliyat
Karaman Evden Eve Nakliyat
Trabzon Evden Eve Nakliyat
sustanon
clenbuterol for sale
Kalıcı Makyaj
dianabol methandienone
Hatay Evden Eve Nakliyat
buy boldenone
F4C5C
ReplyDeleteKocaeli Parça Eşya Taşıma
Mersin Evden Eve Nakliyat
Trabzon Şehir İçi Nakliyat
Aksaray Şehir İçi Nakliyat
Giresun Lojistik
Muğla Şehirler Arası Nakliyat
Gümüşhane Lojistik
Kütahya Lojistik
Hatay Evden Eve Nakliyat
E78AE
ReplyDeleteSamsun Şehirler Arası Nakliyat
Kastamonu Şehir İçi Nakliyat
Malatya Evden Eve Nakliyat
Malatya Lojistik
Malatya Şehirler Arası Nakliyat
Çanakkale Lojistik
Manisa Parça Eşya Taşıma
Denizli Şehirler Arası Nakliyat
Çerkezköy Çatı Ustası
18D03
ReplyDeleteÇerkezköy Parke Ustası
order turinabol
İstanbul Evden Eve Nakliyat
boldenone
deca durabolin
Silivri Çatı Ustası
Bursa Evden Eve Nakliyat
order sustanon
Kocaeli Evden Eve Nakliyat
058F1
ReplyDeleteDenizli Lojistik
Karaman Evden Eve Nakliyat
Çanakkale Parça Eşya Taşıma
Balıkesir Lojistik
Burdur Lojistik
Kırklareli Parça Eşya Taşıma
Mersin Evden Eve Nakliyat
Sincan Fayans Ustası
Bartın Şehirler Arası Nakliyat
68914
ReplyDeleteBayburt Lojistik
Karaman Şehir İçi Nakliyat
Yalova Şehir İçi Nakliyat
AAX Güvenilir mi
Kucoin Güvenilir mi
Tunceli Evden Eve Nakliyat
Kilis Şehir İçi Nakliyat
Muğla Evden Eve Nakliyat
Şırnak Parça Eşya Taşıma
62216
ReplyDeleteOsmaniye Parça Eşya Taşıma
Çanakkale Parça Eşya Taşıma
Flare Coin Hangi Borsada
Amasya Evden Eve Nakliyat
Zonguldak Evden Eve Nakliyat
Elazığ Şehirler Arası Nakliyat
Kırıkkale Şehir İçi Nakliyat
Şırnak Lojistik
Tunceli Lojistik
CD4F6
ReplyDeleteBurdur Evden Eve Nakliyat
Etlik Fayans Ustası
Chat Gpt Coin Hangi Borsada
Pursaklar Parke Ustası
Çerkezköy Bulaşık Makinesi Tamircisi
Bingöl Lojistik
Silivri Boya Ustası
Muş Parça Eşya Taşıma
Batıkent Parke Ustası
74558
ReplyDeleteKarabük Evden Eve Nakliyat
Aksaray Evden Eve Nakliyat
İstanbul Evden Eve Nakliyat
Çerkezköy Evden Eve Nakliyat
for sale dianabol methandienone
fat burner for sale
testosterone enanthate for sale
order oxandrolone anavar
order parabolan
72DA4
ReplyDeleteankara ucretsiz sohbet
rastgele canlı sohbet
telefonda kızlarla sohbet
mobil sesli sohbet
muş kadınlarla görüntülü sohbet
sesli sohbet uygulamaları
igdir yabancı canlı sohbet
mardin goruntulu sohbet
antep canlı sohbet bedava
C5767
ReplyDeleteBinance Referans Kodu
Coin Kazma
Facebook Grup Üyesi Hilesi
Coin Üretme Siteleri
Tesla Coin Hangi Borsada
Bitcoin Kazma Siteleri
Görüntülü Sohbet Parasız
Youtube Abone Satın Al
Kwai Takipçi Satın Al
2C9E0
ReplyDeletepoocoin
defillama
zkswap
poocoin
galagames
poocoin
dcent
eigenlayer
shiba