楼主: ReneeBK
3133 20

MySQL Stored Procedure Programming [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.7537
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2015-4-6 11:54:04 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

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



二维码

扫码加我 拉你入群

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

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

关键词:Programming Procedure Program MySQL Store procedures maintain programs ground learn

本帖被以下文库推荐

沙发
ReneeBK(未真实交易用户) 发表于 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.

藤椅
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:28:10
提示: 作者被禁止或删除 内容自动屏蔽

板凳
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:30:19
提示: 作者被禁止或删除 内容自动屏蔽

报纸
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:31:28
提示: 作者被禁止或删除 内容自动屏蔽

地板
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:33:09
提示: 作者被禁止或删除 内容自动屏蔽

7
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:47:44

Example 8-5. Example of a “nested” transaction using a savepoint

提示: 作者被禁止或删除 内容自动屏蔽

8
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:48:23

Example 8-3. Example of a transaction that uses a savepoint

提示: 作者被禁止或删除 内容自动屏蔽

9
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:49:08

Example 8-4. Alternative to the SAVEPOINT implementation

提示: 作者被禁止或删除 内容自动屏蔽

10
Nicolle(未真实交易用户) 学生认证  发表于 2015-8-15 08:55:38

Example 8-7. Stored procedure with deadlock-handling logic

提示: 作者被禁止或删除 内容自动屏蔽

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-3 02:28