KEMBAR78
MySQL Cursors | PDF | My Sql | Parameter (Computer Programming)
0% found this document useful (0 votes)
283 views13 pages

MySQL Cursors

MySQL cursors allow iterating through query results row-by-row within stored programs. An implicit cursor is provided for each client connection to handle statement processing. Explicit cursors can be created in triggers, functions, and stored procedures to access rows one at a time. Cursors move in a single direction, fetching data row-by-row using declare, open, fetch, and close statements. They are used to repetitively process query results one row at a time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
283 views13 pages

MySQL Cursors

MySQL cursors allow iterating through query results row-by-row within stored programs. An implicit cursor is provided for each client connection to handle statement processing. Explicit cursors can be created in triggers, functions, and stored procedures to access rows one at a time. Cursors move in a single direction, fetching data row-by-row using declare, open, fetch, and close statements. They are used to repetitively process query results one row at a time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

MySQL Cursors

Introduction
 MySQL Cursors are supported inside stored
programs. Whenever a client get a connection
with the server, by default Oracle server
provides an implicit work area to each client
for its internal processing of MySQL
statements.
 This work area is dedicated to a specific

client. This implicit work area is called as


implicit cursor. A client can access the
implicit cursor with the name MySQL.
Introduction
 MySQL Cursors are used for rows repetition
returned by a query on a row-by-row
process.
 SQL commands will function on all the rows

at one time in the program.


Introduction
 Cursors can be created inside the Triggers,
Functions and Stored Procedures.
MySQL Cursors contain 3-properties:
 Asensitive
 Read only
 One directional
Feature
 MySQL cursor moves only in one direction.
Data fetching can be done in only one
direction, and cannot fetch data in opposite
direction.
Syntax of Cursors
 Declare <cursor_name>cursor for<select
statement>
open <cursor_name>;
fetch<cursor_name>into<variable1>,<variable
2>;
close<cursor_name>;
 cursor_name => The name assigned to a

cursor.
 variables => variables are the column values.
Example
 In the above example, curdemo is a input
parameter which accept input values. cur1 is
the attribute used in the cursor. open() is
used to open the cursor, fetch is used to
fetch the row values into names and close
cursor will remove the open cursor for same
minutes. Then the call cursor will execute the
curdemo and return the records(i.e, call
cursor will call the stu_id(2) and it will return
the name(shah)).
Steps for writing the cursor
 Declare – Is a variable length value.
 Open – Opens a cursor variable that is

associate with a query.


 Fetch – Retrieve a specific row and columns.
 Empty – Which contain an empty set.
 Close – Closing of a cursor.
Steps for writing the cursor
 Declare <cursor_name>cursor for<select
statement>
open <cursor_name>;
fetch<cursor_name>into<variable1>,<variable
2>;
close<cursor_name>;
 Cursor_name => The name assigned to a

cursor.
 variables => variables are the column values.
Example
 In the above example, close_cursor is a input
parameter which accept input values. cur1 is
the attribute used in the cursor. open() is
used to open the cursor, fetch is used to
fetch the record values from cursor, select
name will return the name of the record and
close cursor is used to close the cur1. Then
the call cursor will execute the cur1 and
return the records(i.e, call cursor will call the
stu_id(4) and it will return the name(maze)).
Thank You

You might also like