Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Learn about MySQL stored procedures

Current releases of MySQL include "stored procedures". What are they?

You may start by considering stored procedures to be "Macros" - a series of commands bunched together as one, or a complex command which is held within the MySQL daemon and called up by just a simple call. But they then go much further than that, with variables, conditionals, functions and loops ...

Let's set up and use a simple stored procedure:

mysql> DELIMITER !!!
mysql>
mysql> CREATE PROCEDURE orgtypecount() READS SQL DATA
    -> BEGIN
    -> SET @what = 'SELECT count(oid) from orgtype';
    -> PREPARE summat FROM @what;
    -> EXECUTE summat;
    -> END;
    ->
    -> !!!
Query OK, 0 rows affected (0.00 sec)
 
mysql>
mysql> DELIMITER ;


That's a procedure called "orgtypecount" which counts the number of rows in a table called "orgtype" which have a NOT NULL value in the oid column. But you don't have to type the full command in every time you run it now that it's a stored procedure:

mysql> call orgtypecount();
+------------+
| count(oid) |
+------------+
|          4 |
+------------+
1 row in set (0.00 sec)
 
Query OK, 0 rows affected (0.00 sec)
 
mysql>


Wasn't that easy ;-) ... well, as a starter it was, but stored procedures have a complete programming language to them. From a niche interest a while ago, they're becoming more important as time passes, and I'm now adding a handful of examples to our public MySQL course and I'm happy to go into further details on private courses.
(written 2009-10-09)

 
Associated topics are indexed under
S163 - Stored Procedures in MySQL
  [2749] Delegate Question - defining MySQL table relationships as you create the tables - (2010-05-02)
  [2447] MySQL stored procedures / their use on the web from PHP - (2009-10-10)


Back to
Securing MySQL on a production server
Previous and next
or
Horse's mouth home
Forward to
MySQL stored procedures / their use on the web from PHP
Some other Articles
Family Gathering at 404, The Spa
Four aspects - Chamber, Transport, Courses and Hotel
MySQL - efficiency and other topics
Learn about MySQL stored procedures
Securing MySQL on a production server
Potted MySQL installation
Contrasting Cambridge, Bristol and Wiltshire
Variable storage - Perl, Tcl and Python compared
Not your cup of tea?
3603 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2012: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2446_Lea ... dures.html • PAGE BUILT: Fri Feb 3 14:16:04 2012 • BUILD SYSTEM: wizard