SlideShare a Scribd company logo
STORED PROCEDURE
STORED PROCEDURE
 A procedure is a subroutine (like a subprogram) in a
regular scripting language, stored in a database
 In the case of MySQL, procedures are written in MySQL
and stored in the MySQL database/server
 A MySQL procedure has a name, a parameter list, and
SQL statement(s)
STORED PROCEDURES
 Database program modules that are stored and
executed by the DBMS at the server
DELIMITER //
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END //
DELIMITER ;
WHY STORED PROCEDURES
 Reduces Duplication of effort and improves software modularity
 Multiple applications can use the stored procedure vs. the SQL
statements being stored in the application language (PHP)
Reduces communication and data transfer cost between
client and server (in certain situations)
 Instead of sending multiple lengthy SQL statements, the
application only has to send the name and parameters of the
Stored Procedure
Can be more secure than SQL statements
 Permission can be granted to certain stored procedures without
granting access to database tables
DISADVANTAGES OF STORED PROCEDURES
 Difficult to debug
 MySQL does not provide ways for debugging stored
procedures
Many stored procedures can increase memory use
 The more stored procedures you use, the more memory is
used
Can be difficult to maintain and develop stored procedures
 Another programming language to learn
CREATING STORED PROCEDURES
DELIMITER //
CREATE PROCEDURE NAME
BEGIN
SQL STATEMENT
END //
DELIMITER ;
DELIMITER //
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END //
DELIMITER ;
CALLING STORED PROCEDURES
CALL
STORED_PROCEDURE_NAME
CALL GetAllProducts();
Stored procedures
TYPES OF MYSQL PROCEDURES:
1. Procedure with no parameters:
2. Procedure with IN parameter:
3. Procedure with OUT parameter:
4. Procedure with IN-OUT parameter:
1. PROCEDURE WITH NO PARAMETERS:
A procedure without parameters does not
take any input or casts an output
indirectly.
It is simply called with its procedure
name followed by () (without any
parameters).
It is used for simple queries.
EXAMPLE PROCEDURE WITH NO PARAMETERS
delimiter //
create procedure display_book()
-> begin
-> select *from book;
-> end //
call display_book(); //
PARAMETERS
 There may be times where you want to pass
information to the stored procedures
 Getting user input from a form and using that input in a
SQL statement
PROCEDURE WITH IN PARAMETER:
 An IN parameter is used to take a parameter as
input such as an attribute
 When we define an IN parameter in a procedure,
the calling program has to pass an argument to the
stored procedure
 The value of an IN parameter is protected
EXAMPLE PROCEDURE WITH IN PARAMETER:
delimiter //
create procedure update_price
(IN temp_ISBN varchar(10), IN new_price
integer)
-> begin
-> update book set price=new_price
-> where ISBN=temp_ISBN;
-> end; //
call update_price(001, 600); //
PROCEDURE WITH OUT PARAMETER:
 An OUT parameter is used to pass a parameter as
output or display like the select operator, but
implicitly (through a set value)
 The value of an OUT parameter can be changed
inside the procedure and its new value is passed
back to the calling program
 A procedure cannot access the initial value of the
OUT parameter when it starts.
EXAMPLE ON PROCEDURE WITH OUT
PARAMETER:
delimiter //
create procedure
disp_max(OUT highestprice integer)
-> begin
-> select max(price) into
highestprice from book;
-> end; //
call disp_max(@M); //
select @M;
PROCEDURE WITH IN-OUT PARAMETER:
 An INOUT parameter is a combination of IN and OUT
parameters
 It means that the calling program may pass the
argument, and the stored procedure can modify the
INOUT parameter and pass the new value back to the
calling program.
EXAMPLE ON PROCEDURE WITH IN-OUT PARAMETER
ARGUMENTS AND PARAMETERS
DELIMITER //
CREATE PROCEDURE GetOfficeByCountry(IN countryName VARCHAR(25
BEGIN
SELECT * FROM offices WHERE country = countryName;
END //
DELIMITER ;
Defining
Calling
CALL GetOfficeByCountry('USA')
The values being copied from the calling stored procedure are calling
arguments.
The variables being copied into are called parameters.
OUT PARAMETER
DELIMITER //
CREATE PROCEDURE CountOrderByStatus(IN orderStatus
VARCHAR(25), OUT total INT)
BEGIN
SELECT count(orderNumber) INTO total FROM orders WHERE status =
orderStatus;
END//
DELIMITER ;
Defining
Calling
CALL CountOrderByStatus('Shipped',@total);
SELECT @total;
The out parameter is used outside of the stored
procedure.
VARIABLES
 A variable is a name that refers to a value
A name that represents a value stored in the
computer memory
C program
int name=“Amit”;
int age=25
 MySQL
DECLARE name VARCHAR(255)
DECLARE age INT
DELIMITER //
CREATE PROCEDURE declare2(IN value
int,IN name varchar(20))
BEGIN
DECLARE x INT;
DECLARE str VARCHAR(255);
SET x = value;
SET str = name;
SELECT x,str;
END//
DELIMITER ;
CONDITIONALS
THE “IF” STATEMENT
Mysql Syntax
IF if_expression THEN commands
[ELSEIF elseif_expression THEN commands]
[ELSE commands]
END IF;
First line is known as the IF clause
Includes the keyword IF followed by condition followed by the
keyword THEN
 When the IFstatement executes, the condition is tested,
and if it is true the block statements are executed.
Otherwise, block statements are skipped
“IFEXPRESSION”: BOOLEAN EXPRESSIONS AND
OPERATORS
IF STATEMENT
DELIMITER //
CREATE PROCEDURE
GetProductsInStockBasedOnQuantitityLevel(IN p_operator
VARCHAR(255), IN p_quantityInStock INT)
BEGIN
IF p_operator = "<" THEN
select * from products WHERE quantityInStock <
p_quantityInStock;
ELSEIF p_operator = ">" THEN
select * from products WHERE quantityInStock >
p_quantityInStock;
END IF;
END //
DELIMITER ;
IF STATEMENT
 CREATE PROCEDURE
GetProductsInStockBasedOnQuantitityLevel
(IN p_operator VARCHAR(255), IN p_quantityInStock
INT)
The ooperator > or < The number in stock
THE IF STATEMENT
IF p_operator = "<" THEN
select * from products WHERE quantityInStock <
p_quantityInStock;
ELSEIF p_operator = ">" THEN
select * from products WHERE quantityInStock >
p_quantityInStock;
END IF;
LOOPS
 While
 Repeat
 Loop
Repeats a set of commands until some condition
is met
Iteration: one execution of the body of a loop
If a condition is never met, we will have an infinite
loop
WHILE LOOP
WHILE expression DO
Statements
END WHILE
The expression must evaluate
to true or false
while loop is known as a pretest loop
Tests condition before performing an iteration
Will never execute if condition is false to start with
Requires performing some steps prior to the loop
INFINITE LOOPS
 Loops must contain within themselves a way to
terminate
 Something inside a while loop must eventually make
the condition false
 Infinite loop: loop that does not have a way of
stopping
 Repeats until program is interrupted
 Occurs when programmer forgets to include
stopping code in the loop
WHILE LOOP
DELIMITER //
CREATE PROCEDURE WhileLoopProc()
BEGIN
DECLARE x INT;
DECLARE str VARCHAR(255);
SET x = 1;
SET str = '';
WHILE x <= 5 DO
SET str = CONCAT(str,x,',');
SET x = x + 1;
END WHILE;
SELECT str;
END//
DELIMITER ;
WHILE LOOP
 Creating Variables
DECLARE x INT;
DECLARE str VARCHAR(255);
SET x = 1;
SET str = '';
WHILE LOOP
WHILE x <= 5 DO
SET str = CONCAT(str,x,',');
SET x = x + 1;
END WHILE;

More Related Content

PPTX
5. stored procedure and functions
Amrit Kaur
 
PPSX
MS SQL Server
Md. Mahedee Hasan
 
DOC
A must Sql notes for beginners
Ram Sagar Mourya
 
PPTX
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
PPT
PL/SQL
Vaibhav0
 
PPTX
SQL Data types and Constarints.pptx
jaba kumar
 
PPT
SQL select statement and functions
Vikas Gupta
 
5. stored procedure and functions
Amrit Kaur
 
MS SQL Server
Md. Mahedee Hasan
 
A must Sql notes for beginners
Ram Sagar Mourya
 
PL/SQL
Vaibhav0
 
SQL Data types and Constarints.pptx
jaba kumar
 
SQL select statement and functions
Vikas Gupta
 

What's hot (20)

PDF
Exception handling in plsql
Arun Sial
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Joins in SQL
Vigneshwaran Sankaran
 
PPTX
Nested queries in database
Satya P. Joshi
 
PDF
Triggers in SQL | Edureka
Edureka!
 
PDF
PL/SQL TRIGGERS
Lakshman Basnet
 
PPTX
Sql queries presentation
NITISH KUMAR
 
PPTX
trigger dbms
kuldeep100
 
PPTX
Unit 4 plsql
DrkhanchanaR
 
PDF
SQL - RDBMS Concepts
WebStackAcademy
 
PPTX
Sql commands
Pooja Dixit
 
PPTX
Group By, Order By, and Aliases in SQL
MSB Academy
 
PPT
Constraints In Sql
Anurag
 
PPTX
Data types in php
ilakkiya
 
PPTX
Sql Constraints
I L0V3 CODING DR
 
PPT
Database Triggers
Aliya Saldanha
 
PPTX
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
PPTX
SQL Functions
ammarbrohi
 
Exception handling in plsql
Arun Sial
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Joins in SQL
Vigneshwaran Sankaran
 
Nested queries in database
Satya P. Joshi
 
Triggers in SQL | Edureka
Edureka!
 
PL/SQL TRIGGERS
Lakshman Basnet
 
Sql queries presentation
NITISH KUMAR
 
trigger dbms
kuldeep100
 
Unit 4 plsql
DrkhanchanaR
 
SQL - RDBMS Concepts
WebStackAcademy
 
Sql commands
Pooja Dixit
 
Group By, Order By, and Aliases in SQL
MSB Academy
 
Constraints In Sql
Anurag
 
Data types in php
ilakkiya
 
Sql Constraints
I L0V3 CODING DR
 
Database Triggers
Aliya Saldanha
 
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
SQL Functions
ammarbrohi
 
Ad

Similar to Stored procedures (20)

PPTX
Stored procedures in_mysql
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
PL/SQL___________________________________
NiharikaKeshari
 
PPTX
Stored procedures
MuksNoor
 
PPT
SQl
sarankumarv
 
PPTX
Introduction to mysql part 3
baabtra.com - No. 1 supplier of quality freshers
 
PPT
stored.ppt
YashaswiniSrinivasan1
 
PPTX
Procedures and triggers in SQL
Vikash Sharma
 
PPTX
STORED-PROCEDURE.pptxjsjjdjdjcjcjdkksksksk
loreinesel
 
PPTX
Stored procedures with cursor
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Module04
Sridhar P
 
PPTX
DBMS: Week 11 - Stored Procedures and Functions
RashidFaridChishti
 
PPT
Intro to tsql
Syed Asrarali
 
PPT
Intro to tsql unit 14
Syed Asrarali
 
PPT
plsql les01
sasa_eldoby
 
PPTX
Sql Functions And Procedures
DataminingTools Inc
 
PPTX
MS SQL SERVER: Sql Functions And Procedures
sqlserver content
 
PPTX
MS SQLSERVER:Sql Functions And Procedures
sqlserver content
 
PPTX
Advanced DB lab 1 (2).pptx
AdemeCheklie
 
PL/SQL___________________________________
NiharikaKeshari
 
Stored procedures
MuksNoor
 
Procedures and triggers in SQL
Vikash Sharma
 
STORED-PROCEDURE.pptxjsjjdjdjcjcjdkksksksk
loreinesel
 
Module04
Sridhar P
 
DBMS: Week 11 - Stored Procedures and Functions
RashidFaridChishti
 
Intro to tsql
Syed Asrarali
 
Intro to tsql unit 14
Syed Asrarali
 
plsql les01
sasa_eldoby
 
Sql Functions And Procedures
DataminingTools Inc
 
MS SQL SERVER: Sql Functions And Procedures
sqlserver content
 
MS SQLSERVER:Sql Functions And Procedures
sqlserver content
 
Advanced DB lab 1 (2).pptx
AdemeCheklie
 
Ad

More from Prof.Nilesh Magar (9)

PPTX
Decision tree- System analysis and design
Prof.Nilesh Magar
 
PPTX
System concepts- System Analysis and design
Prof.Nilesh Magar
 
PPTX
Trigger in mysql
Prof.Nilesh Magar
 
PPTX
Mysql creating stored function
Prof.Nilesh Magar
 
PPTX
Crash recovery in database
Prof.Nilesh Magar
 
PPSX
Classification & preduction
Prof.Nilesh Magar
 
PPSX
Frequent itemset mining methods
Prof.Nilesh Magar
 
PPTX
Feasibility study
Prof.Nilesh Magar
 
PPT
Data-ware Housing
Prof.Nilesh Magar
 
Decision tree- System analysis and design
Prof.Nilesh Magar
 
System concepts- System Analysis and design
Prof.Nilesh Magar
 
Trigger in mysql
Prof.Nilesh Magar
 
Mysql creating stored function
Prof.Nilesh Magar
 
Crash recovery in database
Prof.Nilesh Magar
 
Classification & preduction
Prof.Nilesh Magar
 
Frequent itemset mining methods
Prof.Nilesh Magar
 
Feasibility study
Prof.Nilesh Magar
 
Data-ware Housing
Prof.Nilesh Magar
 

Recently uploaded (20)

PPTX
IP_Journal_Articles_2025IP_Journal_Articles_2025
mishell212144
 
PPTX
Web dev -ppt that helps us understand web technology
shubhragoyal12
 
PDF
Blitz Campinas - Dia 24 de maio - Piettro.pdf
fabigreek
 
PDF
blockchain123456789012345678901234567890
tanvikhunt1003
 
PPTX
HSE WEEKLY REPORT for dummies and lazzzzy.pptx
ahmedibrahim691723
 
PPTX
INFO8116 -Big data architecture and analytics
guddipatel10
 
PPTX
Future_of_AI_Presentation for everyone.pptx
boranamanju07
 
PDF
Blue Futuristic Cyber Security Presentation.pdf
tanvikhunt1003
 
PDF
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
PPTX
lecture 13 mind test academy it skills.pptx
ggesjmrasoolpark
 
PPTX
Fluvial_Civilizations_Presentation (1).pptx
alisslovemendoza7
 
PPTX
Presentation (1) (1).pptx k8hhfftuiiigff
karthikjagath2005
 
PPTX
Blue and Dark Blue Modern Technology Presentation.pptx
ap177979
 
PPTX
Introduction to Data Analytics and Data Science
KavithaCIT
 
PDF
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
PPTX
M1-T1.pptxM1-T1.pptxM1-T1.pptxM1-T1.pptx
teodoroferiarevanojr
 
PPT
Real Life Application of Set theory, Relations and Functions
manavparmar205
 
PPTX
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
PPTX
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
PPT
From Vision to Reality: The Digital India Revolution
Harsh Bharvadiya
 
IP_Journal_Articles_2025IP_Journal_Articles_2025
mishell212144
 
Web dev -ppt that helps us understand web technology
shubhragoyal12
 
Blitz Campinas - Dia 24 de maio - Piettro.pdf
fabigreek
 
blockchain123456789012345678901234567890
tanvikhunt1003
 
HSE WEEKLY REPORT for dummies and lazzzzy.pptx
ahmedibrahim691723
 
INFO8116 -Big data architecture and analytics
guddipatel10
 
Future_of_AI_Presentation for everyone.pptx
boranamanju07
 
Blue Futuristic Cyber Security Presentation.pdf
tanvikhunt1003
 
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
lecture 13 mind test academy it skills.pptx
ggesjmrasoolpark
 
Fluvial_Civilizations_Presentation (1).pptx
alisslovemendoza7
 
Presentation (1) (1).pptx k8hhfftuiiigff
karthikjagath2005
 
Blue and Dark Blue Modern Technology Presentation.pptx
ap177979
 
Introduction to Data Analytics and Data Science
KavithaCIT
 
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
M1-T1.pptxM1-T1.pptxM1-T1.pptxM1-T1.pptx
teodoroferiarevanojr
 
Real Life Application of Set theory, Relations and Functions
manavparmar205
 
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
From Vision to Reality: The Digital India Revolution
Harsh Bharvadiya
 

Stored procedures

  • 2. STORED PROCEDURE  A procedure is a subroutine (like a subprogram) in a regular scripting language, stored in a database  In the case of MySQL, procedures are written in MySQL and stored in the MySQL database/server  A MySQL procedure has a name, a parameter list, and SQL statement(s)
  • 3. STORED PROCEDURES  Database program modules that are stored and executed by the DBMS at the server DELIMITER // CREATE PROCEDURE GetAllProducts() BEGIN SELECT * FROM products; END // DELIMITER ;
  • 4. WHY STORED PROCEDURES  Reduces Duplication of effort and improves software modularity  Multiple applications can use the stored procedure vs. the SQL statements being stored in the application language (PHP) Reduces communication and data transfer cost between client and server (in certain situations)  Instead of sending multiple lengthy SQL statements, the application only has to send the name and parameters of the Stored Procedure Can be more secure than SQL statements  Permission can be granted to certain stored procedures without granting access to database tables
  • 5. DISADVANTAGES OF STORED PROCEDURES  Difficult to debug  MySQL does not provide ways for debugging stored procedures Many stored procedures can increase memory use  The more stored procedures you use, the more memory is used Can be difficult to maintain and develop stored procedures  Another programming language to learn
  • 6. CREATING STORED PROCEDURES DELIMITER // CREATE PROCEDURE NAME BEGIN SQL STATEMENT END // DELIMITER ; DELIMITER // CREATE PROCEDURE GetAllProducts() BEGIN SELECT * FROM products; END // DELIMITER ;
  • 9. TYPES OF MYSQL PROCEDURES: 1. Procedure with no parameters: 2. Procedure with IN parameter: 3. Procedure with OUT parameter: 4. Procedure with IN-OUT parameter:
  • 10. 1. PROCEDURE WITH NO PARAMETERS: A procedure without parameters does not take any input or casts an output indirectly. It is simply called with its procedure name followed by () (without any parameters). It is used for simple queries.
  • 11. EXAMPLE PROCEDURE WITH NO PARAMETERS delimiter // create procedure display_book() -> begin -> select *from book; -> end // call display_book(); //
  • 12. PARAMETERS  There may be times where you want to pass information to the stored procedures  Getting user input from a form and using that input in a SQL statement
  • 13. PROCEDURE WITH IN PARAMETER:  An IN parameter is used to take a parameter as input such as an attribute  When we define an IN parameter in a procedure, the calling program has to pass an argument to the stored procedure  The value of an IN parameter is protected
  • 14. EXAMPLE PROCEDURE WITH IN PARAMETER: delimiter // create procedure update_price (IN temp_ISBN varchar(10), IN new_price integer) -> begin -> update book set price=new_price -> where ISBN=temp_ISBN; -> end; // call update_price(001, 600); //
  • 15. PROCEDURE WITH OUT PARAMETER:  An OUT parameter is used to pass a parameter as output or display like the select operator, but implicitly (through a set value)  The value of an OUT parameter can be changed inside the procedure and its new value is passed back to the calling program  A procedure cannot access the initial value of the OUT parameter when it starts.
  • 16. EXAMPLE ON PROCEDURE WITH OUT PARAMETER: delimiter // create procedure disp_max(OUT highestprice integer) -> begin -> select max(price) into highestprice from book; -> end; // call disp_max(@M); // select @M;
  • 17. PROCEDURE WITH IN-OUT PARAMETER:  An INOUT parameter is a combination of IN and OUT parameters  It means that the calling program may pass the argument, and the stored procedure can modify the INOUT parameter and pass the new value back to the calling program.
  • 18. EXAMPLE ON PROCEDURE WITH IN-OUT PARAMETER
  • 19. ARGUMENTS AND PARAMETERS DELIMITER // CREATE PROCEDURE GetOfficeByCountry(IN countryName VARCHAR(25 BEGIN SELECT * FROM offices WHERE country = countryName; END // DELIMITER ; Defining Calling CALL GetOfficeByCountry('USA') The values being copied from the calling stored procedure are calling arguments. The variables being copied into are called parameters.
  • 20. OUT PARAMETER DELIMITER // CREATE PROCEDURE CountOrderByStatus(IN orderStatus VARCHAR(25), OUT total INT) BEGIN SELECT count(orderNumber) INTO total FROM orders WHERE status = orderStatus; END// DELIMITER ; Defining Calling CALL CountOrderByStatus('Shipped',@total); SELECT @total; The out parameter is used outside of the stored procedure.
  • 21. VARIABLES  A variable is a name that refers to a value A name that represents a value stored in the computer memory C program int name=“Amit”; int age=25  MySQL DECLARE name VARCHAR(255) DECLARE age INT
  • 22. DELIMITER // CREATE PROCEDURE declare2(IN value int,IN name varchar(20)) BEGIN DECLARE x INT; DECLARE str VARCHAR(255); SET x = value; SET str = name; SELECT x,str; END// DELIMITER ;
  • 24. THE “IF” STATEMENT Mysql Syntax IF if_expression THEN commands [ELSEIF elseif_expression THEN commands] [ELSE commands] END IF; First line is known as the IF clause Includes the keyword IF followed by condition followed by the keyword THEN  When the IFstatement executes, the condition is tested, and if it is true the block statements are executed. Otherwise, block statements are skipped
  • 26. IF STATEMENT DELIMITER // CREATE PROCEDURE GetProductsInStockBasedOnQuantitityLevel(IN p_operator VARCHAR(255), IN p_quantityInStock INT) BEGIN IF p_operator = "<" THEN select * from products WHERE quantityInStock < p_quantityInStock; ELSEIF p_operator = ">" THEN select * from products WHERE quantityInStock > p_quantityInStock; END IF; END // DELIMITER ;
  • 27. IF STATEMENT  CREATE PROCEDURE GetProductsInStockBasedOnQuantitityLevel (IN p_operator VARCHAR(255), IN p_quantityInStock INT) The ooperator > or < The number in stock
  • 28. THE IF STATEMENT IF p_operator = "<" THEN select * from products WHERE quantityInStock < p_quantityInStock; ELSEIF p_operator = ">" THEN select * from products WHERE quantityInStock > p_quantityInStock; END IF;
  • 29. LOOPS  While  Repeat  Loop Repeats a set of commands until some condition is met Iteration: one execution of the body of a loop If a condition is never met, we will have an infinite loop
  • 30. WHILE LOOP WHILE expression DO Statements END WHILE The expression must evaluate to true or false while loop is known as a pretest loop Tests condition before performing an iteration Will never execute if condition is false to start with Requires performing some steps prior to the loop
  • 31. INFINITE LOOPS  Loops must contain within themselves a way to terminate  Something inside a while loop must eventually make the condition false  Infinite loop: loop that does not have a way of stopping  Repeats until program is interrupted  Occurs when programmer forgets to include stopping code in the loop
  • 32. WHILE LOOP DELIMITER // CREATE PROCEDURE WhileLoopProc() BEGIN DECLARE x INT; DECLARE str VARCHAR(255); SET x = 1; SET str = ''; WHILE x <= 5 DO SET str = CONCAT(str,x,','); SET x = x + 1; END WHILE; SELECT str; END// DELIMITER ;
  • 33. WHILE LOOP  Creating Variables DECLARE x INT; DECLARE str VARCHAR(255); SET x = 1; SET str = '';
  • 34. WHILE LOOP WHILE x <= 5 DO SET str = CONCAT(str,x,','); SET x = x + 1; END WHILE;