Your SlideShare is downloading. ×
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Stored procedure
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
152
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Yasirmusthafa pp yasirmusthafapp@gmail.com www.facebook.com/yasirmusthafa twitter.com/yasirmusthafapp in.linkedin.com/in/yasirmusthafapp 8891396749 Stored procedure
  • 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
  • 3. What is a Stored procedure?? • Segment of sql code • Stored in database catalog • Can called later
  • 4. Advantages of stored procedure • Increases performance of application • Reduced traffic • Secure
  • 5. How we create a stored procedure?? delimiter // create procedure csp_insert_tbl_user_role(in role varchar(20)) begin insert into tbl_user_role values(null,role); end // delimiter ;
  • 6. How to call a stored procedure?? call csp_insert_tbl_user_role(null,"employee");
  • 7. Cursor • Why we use cursor ?? To handle a result set inside a stored procedure • A cursor allow you to iterate a set of rows returned by a query and process each row accordingly • mySQL cursor is read only,non-scrollable
  • 8. Working with mySQL cursor 1. DECLARE cursor_name CURSOR FOR SELECT_statement; 2. OPEN cursor_name; 3. FETCH cursor_name INTO variables list; 4. CLOSE cursor_name;
  • 9. NOT FOUND Handler • When we use NOT FOUNF handler? Syntax DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
  • 10. Flow chart
  • 11. Example• delimiter // • Create procedure csp_cur_check_age() • Begin • declare id int; • DECLARE diff int; • DECLARE done INT DEFAULT 0; • DECLARE myCur CURSOR FOR SELECT pk_int_teacher_id,timestampdiff(year,dat_teacher_doj,curdate()) from tbl_teachers; • DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; • OPEN myCur; • teacher_Loop: LOOP • FETCH myCur INTO id,diff; • if diff>32 then • update tbl_teachers set bln_teacher_status=0 where pk_int_teacher_id=id; • end if; • If done=1 THEN • LEAVE teacher_loop; • else • iterate teacher_loop; • END IF; • END LOOP teacher_loop; • CLOSE myCur ; • select vchr_teacher_name,bln_teacher_status from tbl_teachers; • END// • delimiter ;
  • 12. Problem 1 • Create 2 tables tbl_login,tbl_user Write a single stored procedure to insert values into both table Solution Delimiter // Create procedure csp_insert(in username varchar(20),in pass varchar(10),in firstname varchar(20),in lastname varchar(20)) Begin declare fk_login int; Insert into tbl_login values(null,username,pass); select last_insert_id()into fk_login; insert into tbl_users values(null,firstname,lastname,fk_login); end // delimiter ; call csp_insert("yasirmusthafa","yasir123","yasir","musthafa");
  • 13. THANK YOU
  • 14. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 15. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 16. 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 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us

×