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
Stored procedure
Nabeel.C
nabilmohad@gmail.com
www.facebook/ nabilmohad
twitter.com/shafikarassry
in.linkedin.com/in/nabilmohad
+919746477551
STORED PROCEDURE
• A stored procedure is an laready written sql
statement that is saved in the database.
we can run the stored procedure from the
database’s enviornment.
Stored procedures does not execute
automatically.
Pre compailed execution.
Sql server compailes each stored procedure
once and then reutilize the execution plan.
Redused client/server traffic
• Stored procedure reduced the traffic between
application and database server because
instead of sending multiple uncompiled long
SQL commands statement, application only
has to send the stored procedure name and
get the result back. .
Efficient reuse of code and
programming abstraction.
• stored procedure can be used by multiple
users and client programs. If we utlize them in
a planned manner, you will find the
devlopment cycle take less time.
Syntax:-
• DELIMITER
CREATE PROCEDURE procedure_name()
BEGIN
codes;
END
DELIMITER ;
• In order to invoke a stored procedure we use the
following SQL command:
CALL STORED_PROCEDURE_NAME()
• DELIMITER //
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END //
DELIMITER ;
• Call GetAllProducts();
stored procedures with parameters
•
• Parameters make the stored procedure more
flexible and useful. In MySQL, a parameter has
one of three modes IN, OUT and INOUT.
• IN this is the default mode. IN indicates that a
parameter can be passed into stored
procedures but any modification inside stored
procedure does not change parameter.
Suppose you pass parameter Id, which is equal
10, into stored procedure GetAll(Id), after
executing the stored procedure the value of Id
is still 10 even though the GetAll stored
procedure can change the value of it.
• OUT this mode indicates that stored
procedure can change this parameter and
pass back to the calling program.
• INOUT obviously this mode is combined of IN
and OUT mode; you can pass parameter into
stored procedure and get it back with the new
value from calling program.
• DELIMITER //
CREATE PROCEDURE GetOfficeByCountry(IN
countryName VARCHAR(255))
BEGIN
SELECT city, phone
FROM offices
WHERE country = countryName;
END //
DELIMITER ;
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

Stored procedures in_mysql

  • 2.
    Disclaimer: This presentationis 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.
  • 4.
    STORED PROCEDURE • Astored procedure is an laready written sql statement that is saved in the database. we can run the stored procedure from the database’s enviornment. Stored procedures does not execute automatically.
  • 5.
    Pre compailed execution. Sqlserver compailes each stored procedure once and then reutilize the execution plan.
  • 6.
    Redused client/server traffic •Stored procedure reduced the traffic between application and database server because instead of sending multiple uncompiled long SQL commands statement, application only has to send the stored procedure name and get the result back. .
  • 7.
    Efficient reuse ofcode and programming abstraction. • stored procedure can be used by multiple users and client programs. If we utlize them in a planned manner, you will find the devlopment cycle take less time.
  • 8.
    Syntax:- • DELIMITER CREATE PROCEDUREprocedure_name() BEGIN codes; END DELIMITER ; • In order to invoke a stored procedure we use the following SQL command: CALL STORED_PROCEDURE_NAME()
  • 9.
    • DELIMITER // CREATEPROCEDURE GetAllProducts() BEGIN SELECT * FROM products; END // DELIMITER ; • Call GetAllProducts();
  • 10.
    stored procedures withparameters • • Parameters make the stored procedure more flexible and useful. In MySQL, a parameter has one of three modes IN, OUT and INOUT.
  • 11.
    • IN thisis the default mode. IN indicates that a parameter can be passed into stored procedures but any modification inside stored procedure does not change parameter. Suppose you pass parameter Id, which is equal 10, into stored procedure GetAll(Id), after executing the stored procedure the value of Id is still 10 even though the GetAll stored procedure can change the value of it.
  • 12.
    • OUT thismode indicates that stored procedure can change this parameter and pass back to the calling program. • INOUT obviously this mode is combined of IN and OUT mode; you can pass parameter into stored procedure and get it back with the new value from calling program.
  • 13.
    • DELIMITER // CREATEPROCEDURE GetOfficeByCountry(IN countryName VARCHAR(255)) BEGIN SELECT city, phone FROM offices WHERE country = countryName; END // DELIMITER ;
  • 14.
    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