SQL in cursor may be a set of rows alongside a pointer that identifies a current row. it's a database object to retrieve data from a result set one row at a time. it's useful once we want to control the record of a table during a singleton method, in other words, one row at a time.
cursor का size उसके डेटा के अनुसार flexible होता है। SQL cursor को open करने के लिए main memory में कुछ space predefined रखता है, इसलिए cursor की size limited होती है। जब भी कोई query run होती है तो cursor कार्य करता है।
SQL स्टेटमेंट को प्रोसेस करने के लिए MS SQL एक मेमोरी एरिया create करता है, जिसे मैमोरी(context) एरिया भी कहा जाता है। Cursor इस मैमोरी एरिया के लिए पॉइंटर होता है और cursor के द्वारा इस मैमोरी(context) एरिया को नियंत्रित किया जाता है।
Cursor दो प्रकार के होते हैं।:-
a):-Implicit cursor
b):-Explicit cursor
a):-Implicit cursor:- जब भी SQL स्टेटमेंट execute होता है, MS SQLके द्वारा implicit cursor को automatically create कर दिया जाता है।
प्रोग्रामर्स implicit cursor तथा उसमें उपस्थित सूचना को नियंत्रित नही कर सकते है।
MS SQL द्वारा internal processing के लिए जो cursor open किया जाता है उसे implicit cursor कहते है ।
b):- Explicit cursor:- Explicit cursor यूजर-डिफाइंड होता है। Explicit cursor के द्वारा हम मेमोरी (context) एरिया में ज्यादा नियंत्रण कर सकते है।
जब किसी टेबल से कुछ रिकॉर्ड को SQL code block में प्रयोग किया जाता है तब cursor का उपयोग किया जाता है। इस cursor को declare करबे के लिए SQL queries का प्रयोग किया जाता है।
इन दोनों प्रकार के cursor में चार common attributes होते है, जो निम्लिखित है:-
i):-%notfound:-यदि record successfully fetch नही किये गए हो तो true अथवा false वैल्यू return करता है।
ii):-%isopen:-यदि cursor open है तो true अथवा false वैल्यू return करता है।
iii):-%Rowcount:-यह process किये गए record की संख्या return करता है।
iv):-%found:-यदि record सफलतापूर्वक fetch किये गए है तो true अथवा false वैल्यू return करता है।
Explicit cursor management:- Explicit cursor management करने के लिए निम्न steps होते है:-
i):-SQL की select query द्वारा cursor एरिया select करते है।
ii):-Cursor को open करते है।
iii):-Cursor variable में Record को fetch करते है।
Explicit cursor को create करने के लिए निम्नलिखित syntax है:-
[CURSOR cursor_name IS select_statement]
DECLARE
total_rows number(2);
BEGIN
UPDATE customer
SET salary = salary + 600;
IF sql%notfound THEN
dbms_output.put_line('no customers selected');
ELSIF sql%found THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' customers selected ');
END IF;
END
use of a cursor in SQL, types of the cursor in SQL, cursor in SQL example with a stored procedure, sql server cursor example multiple columns, sql server cursor for update, trigger and cursor in sql, cursor in pl/sql
types of cursor in SQL
cursor in SQL minify code
cursor in SQLserver
cursor in SQL
cursor in SQLexample with stored procedure
trigger and cursor in SQL
nested cursor in SQLserver
2020-05-15