全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 winbugs及其他软件专版
3074 20
2015-04-06

MySQL Stored Procedure Programming


Building High-Performance Web Applications in MySQL



Book Description
MySQL Stored Procedure Programming covers a lot of ground. The book starts with a thorough introduction to stored procedures programming and functions, covering the fundamentals of data types, operators, and using SQL in stored procedures. You'll learn how to build and maintain stored programs -- covering transactions, stored functions, and triggers -- and how to call and use MySQL-based stored procedures in a variety of languages, including PHP, Perl, Python, .NET, and Java. This book, destined to be the bible of stored procedure development, is a resource that no real MySQL programmer can afford to do without.
Book Details
Publisher:        O'Reilly Media
By:        Guy Harrison, Steven Feuerstein
ISBN:        978-0-596-10089-6
Year:        2006
Pages:        640
Language:        English
File size:        8 MB
File format:        PDF
Download:       

本帖隐藏的内容

MySQL Stored Procedure Programming.rar
大小:(4.81 MB)

只需: 20 个论坛币  马上下载

本附件包括:

  • MySQL Stored Procedure Programming.pdf




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-5-26 09:43:59
Creating the Procedure

You can create a stored program with the CREATE PROCEDURE , CREATE FUNCTION , or CREATE TRIGGER statement. It is possible to enter these statements directly at the MySQL command line, but this is not practical for stored programs of more than trivial length, so the best thing for us to do is to create a text file containing our stored program text. Then we can submit this file to the database using the command-line client or another tool.

We will use the MySQL Query Browser as a text editor in this example. If you don’t have this tool, you can download it fromhttp://dev.mysql.com/downloads/. Alternately, you could use an OS text editor such as vi, emacs, or Notepad. We like the MySQL Query Browser because of its built-in help system, syntax highlighting, ability to run SQL statements, and lots of other features.

Follow these steps:

  • Run the MySQL Query browser. On Windows, from the Start menu select Programs → MySQL → MySQL Query Browser. On Linux, type mysql-query-browser from the command line.

  • Select File → New Script tab from the menu to create a blank script window.

  • Enter your stored program command text.



Figure 2-1 shows our first stored procedure.

We then use the File → Save As menu option to save our file so that we can execute it from the mysql client.



Figure 2-1. A first stored procedure

This first stored procedure is very simple, but let’s examine it line by line to make sure you understand it completely:

[td]

Line


Explanation


1


Issue the DELIMITER command to set '$$' as the end of a statement. Normally, MySQL regards ";" as the end of a statement, but since stored procedures contain semicolons in the procedure body, we need to use a different delimiter.


3


Issue a DROP PROCEDURE IF EXISTS statement to remove the stored procedure if it already exists. If we don’t do this, we will get an error if we then try to re-execute this file with modifications and the stored procedure exists.


4


The CREATE PROCEDURE statement indicates the start of a stored procedure definition. Note that the stored procedure name "HelloWorld" is followed by an empty set of parentheses "( )". If our stored procedure had any parameters, they would be defined within these parentheses. This stored procedure has no parameters, but we need to include the parentheses anyway, or we will get a syntax error.


5


The BEGIN statement indicates the start of the stored procedure program. All stored programs with more than a single statement must have at least one BEGIN and END block that defines the start and end of the stored program.


6


This is the single executable statement in the procedure: a SELECT statement that returns "Hello World" to the calling program. As you will see later, SELECT statements in stored programs can return data to the console or calling program just like SELECT statements entered at the MySQL command line.


7


The END statement terminates the stored procedure definition. Note that we ended the stored procedure definition with $$ so that MySQL knows that we have completed the CREATE PROCEDURE statement.


With our definition stored in a file, we can now use the mysql client to create and then execute the HelloWorld stored procedure, as shown in Example 2-2.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-8-15 08:28:10
提示: 作者被禁止或删除 内容自动屏蔽
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-8-15 08:30:19
提示: 作者被禁止或删除 内容自动屏蔽
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-8-15 08:31:28
提示: 作者被禁止或删除 内容自动屏蔽
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-8-15 08:33:09
提示: 作者被禁止或删除 内容自动屏蔽
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群