Hello Friend ! इस पोस्ट में आपको SQL में Cursor के बारें में बताया जायेगा तथा यह क्या होता है, इसके बारें में भी बात करेगे, तो चलिए शुरू करते है:-
है, तो cursors का उपयोग किया जाता है।
Cursor में जो Data Store होता है उसे Active Data Set कहा जाता है। Oracle DBMS में मुख्य memory set में एक और predefined area है, जिसके भीतर cursors खोले जाते हैं। इसलिए cursors का आकार इस pre-defined area के आकार द्वारा (Limited) सीमित है।
SQL statement को process करने के लिए oracle एक memory area create करता है, जिसे context area भी कहा जाता है।
Cursor इस memory area के लिए point होता है और cursor के द्वारा इस मैमोरी (context) एरिया को नियंत्रित किया जाता है।
Cursor का size उसके डेटा के अनुसार flexible होता है। Oracle cursor को open करने के लिए main memory में कुछ space predefined रखता है इसलिए cursor की size limited होती है। जब भी कोई query run होती है तो cursor कार्य करता है।
Oracle द्वारा internal processing के लिए जो cursor open किया जाता है उसे implicit cursor कहते है।
Explicit cursor user define होता है। explicit cursor के द्वारा हम मेमोरी (context) area में ज्यादा नियंत्रण कर सकते है।
जब किसी table से कुछ record को PL/SQL code block में प्रयोग किया जाता है तब cursor का उपयोग किया जाता है। इस cursor को declare करबे के लिए SQL queries का प्रयोग किया जाता है।
इन दोनों प्रकार के cursor में चार common attributes होते है.
CURSOR cursor_name IS
select_statement;
cursor_name – A
suitable name for the cursor.
select_statement – A
select query which returns multiple rows
SQL CURSOR in Hindi
Use of Cursor in SQL server
Cursor का मुख्य कार्य डेटा को पुनः प्राप्त (retrieve) करना है, एक समय में एक row, result set से, SQL commands के विपरीत जो result में सभी rows को एक समय में सेट करते हैं। जब एक database table में उपयोगकर्ता को सिंगलटन फैशन में या row by row में update records करने की आवश्यकता होतीहै, तो cursors का उपयोग किया जाता है।
Cursor में जो Data Store होता है उसे Active Data Set कहा जाता है। Oracle DBMS में मुख्य memory set में एक और predefined area है, जिसके भीतर cursors खोले जाते हैं। इसलिए cursors का आकार इस pre-defined area के आकार द्वारा (Limited) सीमित है।
SQL statement को process करने के लिए oracle एक memory area create करता है, जिसे context area भी कहा जाता है।
Cursor इस memory area के लिए point होता है और cursor के द्वारा इस मैमोरी (context) एरिया को नियंत्रित किया जाता है।
Cursor का size उसके डेटा के अनुसार flexible होता है। Oracle cursor को open करने के लिए main memory में कुछ space predefined रखता है इसलिए cursor की size limited होती है। जब भी कोई query run होती है तो cursor कार्य करता है।
Cursor Actions
- Declare Cursor:- Result set करने वाले SQL statement को परिभाषित करके एक कर्सर घोषित (Declared) किया जाता है।
- Open:- Cursor के द्वारा परिभाषित (defined) SQL statement को execute करके एक cursor खोला और आबाद (populated) किया जाता है।
- Fetch:- जब cursor खोला जाता है, तो डेटा हेर-फेर करने के लिए rows को एक-एक करके या block में cursor से लाया जा सकता है।
- Close:- Data हेरफेर के बाद, cursor को स्पष्ट रूप से बंद (close) करें।
- De-allocate:- Finally, कर्सर की परिभाषा को हटा दें और cursor से जुड़े सभी system resources को छोड़ दें।
- Implicit cursor
- Explicit cursor
1. Implicit cursor
जब भी SQL स्टेटमेंट execute होता है, Oracle के द्वारा implicit cursor को automatically create कर दिया जाता है, जब statement के लिए कोई explicit cursor नही होता है।Oracle द्वारा internal processing के लिए जो cursor open किया जाता है उसे implicit cursor कहते है।
2. Explicit cursor
Explicit cursor को PL/SQL block के घोषणा खंड (declaration section) में परिभाषित किया गया है। यह एक SELECTstatement पर बनाया गया है, जो एक से अधिक row देता है। cursor के लिए एक उपयुक्त (suitable) नाम है।Explicit cursor user define होता है। explicit cursor के द्वारा हम मेमोरी (context) area में ज्यादा नियंत्रण कर सकते है।
जब किसी table से कुछ record को PL/SQL code block में प्रयोग किया जाता है तब cursor का उपयोग किया जाता है। इस cursor को declare करबे के लिए SQL queries का प्रयोग किया जाता है।
इन दोनों प्रकार के cursor में चार common attributes होते है.
- %Isopen यदि cursor open है तो true अथवा false वैल्यू return करता है।
- %found यदि record सफलतापूर्वक fetch किये गए है तो true अथवा false value return करता है।
- %Notfound यदि record successfully fetch नही किये
गए हो तो true अथवा false value return करता है। - %Rowcount यह process किये गए record की संख्या return करता है।
CURSOR cursor_name IS
select_statement;
cursor_name – A
suitable name for the cursor.
select_statement – A
select query which returns multiple rows
How to use Explicit Cursor?
There are four steps in using an Explicit Cursor.- Declaration section में cursor को DECLARE करें।
- OPEN the cursor in the Execution Section.
- कर्सर से PL/SQL variables या records Section में data records करें।
- PL/SQL Block को end करने से पहले cursor को execution section में Close करे दे।