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
4. 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.
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 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.
8. 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()
9. • DELIMITER //
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END //
DELIMITER ;
• Call GetAllProducts();
10. 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.
11. • 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.
12. • 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.
13. • DELIMITER //
CREATE PROCEDURE 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