in Technology by
What is Cursor? How to use a Cursor?

1 Answer

0 votes
by

A database cursor is a control structure that allows for traversal of records in a database. Cursors, in addition, facilitates processing after traversal, such as retrieval, addition and deletion of database records. They can be viewed as a pointer to one row in a set of rows.

Working with SQL Cursor

DECLARE @name VARCHAR(50) 	 /* Declare All Required Variables */

DECLARE db_cursor CURSOR FOR 	 /* Declare Cursor Name*/
SELECT name
FROM myDB.students
WHERE parent_name IN ('Sara', 'Ansh')

OPEN db_cursor 	 /* Open cursor and Fetch data into @name */ 
FETCH next
FROM db_cursor
INTO @name

CLOSE db_cursor 	 /* Close the cursor and deallocate the resources */
DEALLOCATE db_cursor
    • DECLARE a cursor after any variable declaration. The cursor declaration must always be associated with a SELECT Statement.
    • Open cursor to initialize the result set. The OPEN statement must be called before fetching rows from the result set.
    • FETCH statement to retrieve and move to the next row in the result set.
    • Call the CLOSE statement to deactivate the cursor.
    • Finally use the DEALLOCATE statement to delete the cursor definition and release the associated resources.

Related questions

0 votes
    I am trying to simulate the look and feel of a Firefox disabled text input: textarea and input text. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I am trying to simulate the look and feel of a Firefox disabled text input: textarea and input text. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
0 votes
    What is cursor and why it is required?...
asked Dec 17, 2020 in Technology by JackTerrance
0 votes
    What are the cursor attributes used in PL/SQL?...
asked Dec 17, 2020 in Technology by JackTerrance
0 votes
    I'm running a RPi 3 as an infoscreen. Im just starting chromium with the xinit command from rc. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Let's say I have the following simple table variable: declare @databases table ( DatabaseID int, Name ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I haven't been able to find this explicitly stated anywhere yet, but a bunch of examples I've ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    key is used to move the cursor in the adjoining cell of a table Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    9. no c. Exit This blinking line is called as a. Pointer b. font C. cursor 10. To work with any text, it ... to save a file, press 14 Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    13. Pressing the Home Key, moves the cursor to the__________ (a) Beginning of the line (b) Beginning of the ... Beginning of the page Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    If the cursor is placed at the end of the file , then___ button is pressed to delete the text. 1. delete 2. back space 3. enter 4. tab Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    While I try to answer any question in brainly app, the cursor is moving from right to left instead of moving ... Why does it happen? Select the correct answer from above options...
asked Nov 29, 2021 in Education by JackTerrance
0 votes
    pointing stick design isometric miniature joystick that is primarily used in laptops as a cursor pointing device TRUE OR FALSE Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    pointing stick design isometric miniature joystick that is primarily used in laptops as a cursor pointing device TRUE OR FALSE Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
...