2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
14. Example..
DELIMITER $$
CREATE PROCEDURE build_email_list (INOUT email_list varchar(4000))
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE v_email varchar(100) DEFAULT "";
-- declare cursor for employee email
DEClARE email_cursor CURSOR FOR SELECT email FROM employees;
-- declare NOT FOUND handler
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
15. Ctnd..
OPEN email_cursor;
get_email: LOOP
FETCH email_cursor INTO v_email;
IF v_finished = 1 THEN
LEAVE get_email;
END IF;
-- build email list
SET email_list = CONCAT(v_email,“,",email_list);
END LOOP get_email;
CLOSE email_cursor;
END$$
SET @email_list = "";
CALL build_email_list(@email_list);
SELECT @email_list;
16. Write a single stored procedure to insert values
into both table?
DELIMITER $$
CREATE PROCEDURE double_insert( usr CHAR(12), pass CHAR(12))
BEGIN
START TRANSACTION;
INSERT INTO tbl_user VALUES (usr,NULL);
INSERT INTO tbl_login VALUES (NULL,usr, pass);
COMMIT;
END$$
DELIMITER ;
SET @username = 'baabtra';
SET @password = '321';
CALL double_insert(@username,@password);
SELECT * FROM tbl_user;
SELECT * FROM tbl_login;
18. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
19. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
IKK Road,
East Hill, Kozhikode
Kerala, India.
Ph: + 91 – 495 30 63 624
NIT-TBI,
NIT Campus, Kozhikode,
Kerala, India.