|
Mysql Application & Query Optimization, Questions, Indexes, Bugs.
Author |
Message |
debuser
|
 |
Post subject: How to use a mysql stored procedure | Posted: Mon Nov 21, 2011 4:12 pm |
|
Joined: Thu Aug 06, 2009 2:48 am Posts: 105
|
How to use a mysql stored procedure
Unlike other sql commands, stored procedures need to be called. Therefore the CALL command needs to be used: Code: mysql> CALL stored_procedure_name('argument1,'argument2');
|
|
|
|
|
|
Darwin
|
 |
Post subject: Re: How to use a mysql stored procedure | Posted: Tue Nov 22, 2011 1:23 am |
|
Joined: Tue Nov 08, 2011 7:57 am Posts: 3
|
A stored procedure is a procedure (like a subprogram in a regular computing language) that is stored (in the database). Correctly speaking, MySQL supports "routines" and there are two kinds of routines: stored procedures which you call, or functions whose return values you use in other SQL statements the same way that you use pre-installed MySQL functions like pi(). I'll use the word "stored procedures" more frequently than "routines" because it's what we've used in the past, and what people expect us to use.
A stored procedure has a name, a parameter list, and an SQL statement, which can contain many more SQL statements. There is new syntax for local variables, error handling, loop control, and IF conditions. Here is an example of a statement that creates a stored procedure.
CREATE PROCEDURE procedure1 /* name */ (IN parameter1 INTEGER) /* parameters */ BEGIN /* start of block */ DECLARE variable1 CHAR(10); /* variables */ IF parameter1 = 17 THEN /* start of IF */ SET variable1 = 'birds'; /* assignment */ ELSE SET variable1 = 'beasts'; /* assignment */ END IF; /* end of IF */ INSERT INTO table1 VALUES (variable1); /* statement */ END /* end of block */
What I'm going to do is explain in detail all the things you can do with stored procedures. We'll also get into another new database object, triggers, because there is a tendency to associate triggers with stored procedures.
|
|
|
|
|
|
Topics related to - "How to use a mysql stored procedure" |
Topics |
Author |
Replies | Views |
Last post |
 |
|
Mysql> stored procedure for inserting in multiple tables \w common key
|
debuser |
1 |
6496 |
Tue Nov 22, 2011 5:17 pm
debuser
|
 |
|
Mysql command to show stored procedures
|
debuser |
0 |
1990 |
Mon Nov 21, 2011 3:57 pm
debuser
|
 |
|
Mysql show stored procedures and functions
|
mandrei99 |
0 |
2860 |
Mon Nov 18, 2013 9:06 am
mandrei99
|
 |
|
MySql doesn't start: libexec/mysqld: File './mysql-bin.index' not found (Errcode: 13)
|
debuser |
0 |
3220 |
Mon Feb 22, 2010 1:43 pm
debuser
|
 |
|
Mysql: add column to table
|
debuser |
1 |
4265 |
Fri Oct 08, 2010 1:38 am
sonee4
|
 |
 |
Rename MySql table
|
debuser |
1 |
2373 |
Fri Oct 08, 2010 1:36 am
sonee4
|
 |
|
MySql rename table
|
admin |
2 |
2857 |
Mon Nov 28, 2011 3:39 am
Darwin
|
 |
 |
Mysql: Cleaning binary logs
|
debuser |
1 |
2772 |
Tue May 18, 2010 9:45 am
designeru
|
 |
 |
Mysql change column's default value
|
debuser |
0 |
2794 |
Thu Aug 12, 2010 3:43 am
debuser
|
 |
|
Mysql drop (remove) unique key
|
mandrei99 |
0 |
2722 |
Wed Jan 14, 2015 7:53 pm
mandrei99
|
|
Users browsing this forum: No registered users and 0 guests |
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
News Site map SitemapIndex RSS Feed Channel list
|
|