Categories
MySQL

Cursor in MySQL stored procedures

Cursor allows you to iterate a group of rows fetched by a query and process each row. It is read only, non-scrollable and asensitive. Declare a cursor: DECLARE <cursor_title> CURSOR FOR SELECT_statement; Open a cursor: OPEN <cursor_title>; Fetch cursor: FETCH <cursor_title> INTO variables list; Close cursor: CLOSE <cursor_title>;

Categories
MySQL

Loop in MySQL stored procedures

MySQL allows you to loop statement for executing a block repeatedly based on a condition. These are like WHILE, REPEAT and LOOP. WHILE LOOP: It checks the expression at the beginning of each iteration. Example: DELIMITER $$ CREATE PROCEDURE MyWhileLoop() BEGIN DECLARE x  INT; SET x = 1; WHILE x  <= 10 DO SET  x […]

Categories
MySQL

Listing stored procedures in MySQL

In MySQL you can list or show all stored procedures and manage more efficiently. Display source code of stored procedure: Use SHOW CREATE PROCEDURE statement to display source code of a particular stored procedure. SHOW CREATE PROCEDURE GetAllUsers; Display characteristics of stored procedure: Use SHOW PROCEDURE STATUS to list all stored procedures. SHOW PROCEDURE STATUS […]

Categories
MySQL

MySQL stored procedure parameters and variables

All the stored procedure needs parameters to make more flexible. It has one of these three modes i.e. IN, OUT or INOUT. IN: Default mode i.e. calling program has to pass an argument to the stored procedures and value of IN parameter is changed inside of stored procedure even after stored procedure ends, the values […]