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

preview_player
Показать описание
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 :
===============

Other Tutorials
===============
Wordpress Customizations:
---------------------------------
and many more...

Javascript framework:
----------------------------------

PHP Frameworks:
----------------------------------

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 :)
Рекомендации по теме
Комментарии
Автор

You are among the best online trainers I have met, to me accent is not an issue as long as I understand. In fact I love your the accent, I bet many people understand these because of your accent, if you use slaying we could not understand...

omarykitenge
Автор

You're the best, you showed the exact loop statement that I needed, thank you!

sosmanoriginal
Автор

I finally figured out the cursor syntax. Thanks for this video

maragee
Автор

I click on go button... again have some error!? (With a very friendly voice) . You made my day sir! thanks for the good content.

sherabpereira
Автор

🙏🙏Very helpful and 👍👍well 😍😍made video for learning

computerlearningbyargusaca
Автор

How to use nested cursor ..please tell me

prabhuk
Автор

Hi sir, I need to give values for IN in the sql select statement . Eg: "SELECT name from tbl_name where id IN(145, 146)". So how can I give these values into the Select statement?

anjanakr
Автор

Nice video.. thank you.. plz work on your accent sir

ajinzrathod