Hello Everyone, Can anyone explain to me how to use a cursor and what is it exactly? Actually, I have checked the syntax with the help of this source but I am looking for depth information regarding this. If anyone knows please explain me.
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
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |