Use HANDLER Statement in Cursors
Use HANDLER Statement in Cursor is used to define a set of data rows where we perform operation on a row by row basis. The Cursor help you to return a result set and return directly to the caller of the client or SQL procedure.
Understand with Example
The Tutorial illustrate an example from 'Use HANDLER Statement in Cursors'. To elaborate this, we create a table 'Stu_Table'. The create table statement create a table 'Stu_Table' with table attribute like field name and respective data type.
Create Table Stu_Table
Insert data into Stu_Table
The insert into add the rows or records into the table 'Stu_Table'.
Now, we use Cursor for the above table 'Stu_Table'. Begin with create procedure create a procedure curdemo. The Query begins with a begin keyword that include declare statement used to define the variable and its data type. Each begin keyword end with a end statement pair. The OPEN Cursor open the cur1 which built a result set. The repeat statement in SQL include a set of statements to be executed until a condition evaluated at the end of the REPEAT statement hold true. The fetch curl1 is used to obtain the records into variable 'name'. The select name return you all the row which satisfy the condition. The close cur1 close the cursor cur1, when cur1 is no longer to be used.
To call a Cursor we use the given syntax below: