Home Database Mysql Tutorial Mysql那些事儿之(十二)存储过程_MySQL

Mysql那些事儿之(十二)存储过程_MySQL

Jun 01, 2016 pm 01:39 PM
database html storage

bitsCN.com


Mysql那些事儿之(十二)存储过程

 

相关链接:

Mysql那些事儿之(一)mysql的安装

http:///database/201210/162314.html;

Mysql那些事儿之(二)有关数据库的操作

http:///database/201210/162315.html;

Mysql那些事儿之(三)有关数据表的操作

http:///database/201210/162316.html;

Mysql那些事儿之(四)数据表数据查询操作

http:///database/201210/162317.html;

Mysql那些事儿之(五)操作时间

http:///database/201210/162318.html;

Mysql那些事儿之(六)字符串模式匹配

http:///database/201210/163969.html;

Mysql那些事儿之(七)深入select查询

http:///database/201210/163970.html;

Mysql那些事儿之(八)索引

http:///database/201210/163971.html;

Mysql那些事儿之(九)常用的函数

http:///database/201210/164229.html;

Mysql那些事儿之(十)触发器一

http:///database/201210/164516.html

Mysql那些事儿之(十一)触发器二

http:///database/201210/164766.html

 

存储过程是经过编译之后存放在数据库中的sql语句集合。

存储过程怎么写

看例子:

存储过程的语法

Sql代码  

create procedure proc_name (proc_peremeter1,.....)  --存储过程名称和参数  

[characteristic ....]   

routine_body  --存储过程   

调用存储过程的语法

Sql代码  

call proc_name  --调用存储过程  

示例 创建存储过程

当然创建存储过程之前先建立相关的表,为了学习只建立一个简单的表结构;

Sql代码  

CREATE TABLE filmall (  

  id smallint(5) NOT NULL,  

  film_id smallint(6) NOT NULL,  

  name varchar(40) DEFAULT NULL,  

  store_id smallint(6) NOT NULL,  

  txt text,  

  PRIMARY KEY (`id`)  

) ;      

在数据表里插入数据。

写一个简单的存储过程:

Sql代码  

--存储过程的名称为proc_film_store,参数为3个:前面两个为输入,后面一个为输出  

Sql代码  

delimiter $$  

Sql代码  

create procedure proc_film_store (IN p_film_id INT,IN p_store_id INT,OUT p_film_count INT)  

BEGIN  

SELECT txt FROM filmall WHERE film_id = p_film_id AND store_id = p_store_id;  

SELECT FOUND_ROWS() INTO p_film_count;  --将条数放入变量中  

END $$  

Sql代码  

delimiter ;  

 现在就可以调用存储过程了。

Sql代码  

call proc_film_store(1,1,@a);---输入参数  

--执行完之后会输出查询出来的数据  

 

--输出查询到的条数  

select @a;  

 存储过程就OK了。

Sql代码  

--还有一点要说明的是,书写存储过程时,一般会用到如下命令  

--书写存储过程之前,改变结束符  

delimiter $$  --这个语句的意思是将结尾符;替换为$$  

--写完存储过程之后,再将结束符改回来  

delimiter ;  

 

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles