MySQL Stored Procedure Beginners Tutorial #14 - Basics of Cursor in MySQL Stored Procedure | Cursor

Published: 04 August 2019
on channel: Online Web Tutor
29,278
273

In this video we'll see:

Basics of Cursor in MySQL Stored Procedure | Cursor

ABOUT MYSQL CURSOR
============================

MySQL cursor in stored procedures to iterate through a result set returned by a SELECT
statement.

To handle a result set inside a stored procedure, we use a cursor. A cursor allows you to
iterate a set of rows returned by a query and process each row accordingly.


SYNTAX TO FOLLOW TO USE CURSOR
==================

1. DECLARE cursor_name CURSOR FOR SELECT_statement;

2. OPEN cursor_name;

3. DECLARE CONTINUE HANDLER FOR NOT FOUND // termination statement

4. FETCH cursor_name INTO variables list;

5. CLOSE cursor_name;

Example:

BEGIN

DECLARE finished int default 0;

DECLARE emails_list varchar(500) default "";

DECLARE email varchar(50) default "";

DECLARE user_data CURSOR FOR SELECT email from tbl_users limit 5;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;

OPEN user_data;

get_user_email: LOOP

FETCH user_data INTO email;

IF finished = 1 THEN

LEAVE get_user_email;

END IF;

SET emails_list = CONCAT(emails_list,", ",email);

END LOOP get_user_email;

CLOSE user_data;

SELECT emails_list;

END

SOCIAL :
===============
Subscribe :    / @onlinewebtutor  
FACEBOOK :   / onlinewebtutorhub  
TWITTER:   / owthub  
BLOG: https://onlinewebtutorhub.blogspot.in/

Other Tutorials
===============
Wordpress Customizations:
---------------------------------
Wordpress Theme (Hindi): https://goo.gl/MZ8maF
Wordpress Widget (Hindi): https://goo.gl/Dc2htn
Wordpress Plugin (English): https://goo.gl/BA7dYG
Wordpress Theme Options (English): https://goo.gl/Vjv3Ub
Wordpress JSON Rest API (English): https://goo.gl/SVQRQR
Wordpress JSON Rest API (Hindi): https://goo.gl/NNWfKa
and many more...

Javascript framework:
----------------------------------
Learn backbone.js here! (English) : https://goo.gl/Qd2Pcs
Learn Vue JS here ! (Hindi): https://goo.gl/MVtsmh

PHP Frameworks:
----------------------------------
Laravel tutorial (Hindi): https://goo.gl/Nh9qJk
CakePHP tutorial (Hindi): https://goo.gl/uRsS3G

Tags
----------------------------------
mysql stored procedure,
Stored Procedures - MySQL,
Stored Procedures in MySQL and PHP,
SQL Stored Procedures,
MySQL Stored Procedure Tutorial,
MySQL Stored Procedure & MySQL Functions Guide,
mysql stored procedure for beginners,
Beginners' guide to stored procedures with MySQL,
Getting Started with MySQL Stored Procedures,
mysql stored procedure development for beginners,
mysql stored procedure from scratch,
online web tutor mysql stored procedures,
online web tutor sanjay,

Thanks
Online Web Tutor
Keep learning and Sharing :)


Watch video MySQL Stored Procedure Beginners Tutorial #14 - Basics of Cursor in MySQL Stored Procedure | Cursor online, duration hours minute second in high quality that is uploaded to the channel Online Web Tutor 04 August 2019. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 29,278 times and liked it 273 visitors.