Home Database Mysql Tutorial MySQL5新特点(存储过程)

MySQL5新特点(存储过程)

Jun 07, 2016 pm 04:04 PM
m storage support Features process

支持存储过程是MySQL5中一个很重要的新增特性。虽然有些用户不希望将反映业务逻辑的流程通过存储过程封装在数据库中,但大多数的数据库管理人员还是非常喜欢在数据库中能使用存储过程这一功能,因为存储过程有很多好处: 用户可以重用代码和更改控制 -和将业

支持存储过程是MySQL5中一个很重要的新增特性。虽然有些用户不希望将反映业务逻辑的流程通过存储过程封装在数据库中,但大多数的数据库管理人员还是非常喜欢在数据库中能使用存储过程这一功能,因为存储过程有很多好处:
用户可以重用代码和更改控制
-和将业务逻辑流程写入多个应用程序不同的是,用户只需要写 一次存储过程就可以立刻使用许多应用程序来调用该过程,从而实现特定的业务逻辑流程。数据库管理员也可以通过标准的管理函数来处理不同版本中的数据库资源,比如数据库结构 和安全权限等。
可以获得快速的性能
-管理员可以存储过程中使用循环结构来执行多个SQL语句,而之前应用程序每次只能执行一条SQL语句,效率明显得到提高,也可以把复杂的多个SQL语句写入一个存储过程,不太熟练SQL语句的用户可以直接调用该存储过程,从而避免了在书写复杂SQL语 句时可能出现的错误。
更容易的安全管理特性
-对于一个服务大量不同用户的复杂数据库来说,将数量巨大的数据对象的使用权限分配给不同用户是相当费时的,使用存储过程以后,就可以在过程级进行权限 分配的任务,比如,当用户的一个SQL查询语句需要访问10张不同的表时,若不用存储过程, 就需要为该用户进行10次不同的表许可权限分配,而使用存储过程后只需要对含有该SQL查询 语句的存储过程分配一次许可权限就可以了。
减少了网络通信流量
-原先通过网络的多次调用,写入单个存储过程中放在服务器端后,进行一次存储过程调用就可以完成,从而减少了过量的网络通信流量。
很象DB2数据库,MySQL5中的存储过程也完全符合ANSI SQL 2003标准,非常方便开发人员和数据库管理员学习和使用,而且select查询语句的返回结果也很直观,无须专用的调用包和参考游标,这点类似于微软SQLserver和sybase数据库,下面是一个关于输出的例子:

mysql> delimiter //
mysql> create procedure top_broker()
    -> select a.broker_id,
    ->        a.broker_first_name,
    ->        a.broker_last_n
    ->        sum(broker_commission) total_commissions
    ->   from broker a,
    ->        client_transaction b
    ->   where a.broker_id=b.broker_id
    -> group by a.broker_id,
    ->        a.broker_first_name,
    ->        a.broker_last_name
    -> order by 4 desc;
    -> //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call top_broker();
Copy after login

为了处理标准的查询输出,MySQL5的存储过程中支持了许多常见的开发构造,比如:

输入/输出参数;
变量定义;
带EXIST检查的循环;
逻辑条件判断(if,case等);
条件处理柄;
存储过程调用存储过程;
对事务处理类数据库表的“提交/撤销”功能支持;
数据定义语句等等。
Copy after login
数据库开发和管理人员可以通过create,alter,drop,grant来具体操作MySQL5中的存储过程, 除了获得元数据的特殊存储过程,还可以通过如下方法来操作存储过程:
使用show procedure status函数;
查询mysql.proc内置表;
使用MySQL5的另一个新特性-information_schema数据字典来实现。
Copy after login

(51CTO.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 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)

Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Mar 07, 2024 pm 10:43 PM

This website reported on March 7 that Dr. Zhou Yuefeng, President of Huawei's Data Storage Product Line, recently attended the MWC2024 conference and specifically demonstrated the new generation OceanStorArctic magnetoelectric storage solution designed for warm data (WarmData) and cold data (ColdData). Zhou Yuefeng, President of Huawei's data storage product line, released a series of innovative solutions. Image source: Huawei's official press release attached to this site is as follows: The cost of this solution is 20% lower than that of magnetic tape, and its power consumption is 90% lower than that of hard disks. According to foreign technology media blocksandfiles, a Huawei spokesperson also revealed information about the magnetoelectric storage solution: Huawei's magnetoelectronic disk (MED) is a major innovation in magnetic storage media. First generation ME

What exactly is self-media? What are its main features and functions? What exactly is self-media? What are its main features and functions? Mar 21, 2024 pm 08:21 PM

With the rapid development of the Internet, the concept of self-media has become deeply rooted in people's hearts. So, what exactly is self-media? What are its main features and functions? Next, we will explore these issues one by one. 1. What exactly is self-media? We-media, as the name suggests, means you are the media. It refers to an information carrier through which individuals or teams can independently create, edit, publish and disseminate content through the Internet platform. Different from traditional media, such as newspapers, television, radio, etc., self-media is more interactive and personalized, allowing everyone to become a producer and disseminator of information. 2. What are the main features and functions of self-media? 1. Low threshold: The rise of self-media has lowered the threshold for entering the media industry. Cumbersome equipment and professional teams are no longer needed.

Git installation process on Ubuntu Git installation process on Ubuntu Mar 20, 2024 pm 04:51 PM

Git is a fast, reliable, and adaptable distributed version control system. It is designed to support distributed, non-linear workflows, making it ideal for software development teams of all sizes. Each Git working directory is an independent repository with a complete history of all changes and the ability to track versions even without network access or a central server. GitHub is a Git repository hosted on the cloud that provides all the features of distributed revision control. GitHub is a Git repository hosted on the cloud. Unlike Git which is a CLI tool, GitHub has a web-based graphical user interface. It is used for version control, which involves collaborating with other developers and tracking changes to scripts and

The meaning and characteristics of PHP version NTS The meaning and characteristics of PHP version NTS Mar 26, 2024 pm 12:39 PM

PHP is a popular open source scripting language that is widely used in web development. NTS in the PHP version is an important concept. This article will introduce the meaning and characteristics of the PHP version NTS and provide specific code examples. 1. What is PHP version NTS? NTS is a variant of the PHP version officially provided by Zend, which is called NotThreadSafe (non-thread safe). Usually PHP versions are divided into two types: TS (ThreadSafe, thread safety) and NTS

What is LEO coin? What are the characteristics of LEO coins? What is LEO coin? What are the characteristics of LEO coins? Mar 06, 2024 am 09:31 AM

LEO Coin: LEO Coin, the native token of Binance Exchange, is the native token released by Binance Exchange and was launched in 2019. As a multi-functional utility token, LEO Coin provides Binance users with a range of benefits and privileges. Features of LEO coins: Transaction fee discount: Holding LEO coins can enjoy a discount on Binance exchange transaction fees, up to 25%. VIP membership: Based on the number of LEO coins held, users can obtain different VIP membership levels and enjoy more exclusive benefits. Voting rights: LEO coin holders have the right to vote on major decisions of Binance Exchange and participate in platform governance. Ecosystem applications: LEO coins can be used to pay for various services and products in the Binance ecosystem, such as Binance Launchpad, Binance DEX

What is Axelar Coin? What are the characteristics of Axelar coin? What is Axelar Coin? What are the characteristics of Axelar coin? Mar 06, 2024 am 10:20 AM

Axelar: The future of cross-chain interoperability Axelar is a cross-chain communication protocol designed to solve interoperability issues between different blockchains. With Axelar, developers can easily build cross-chain applications to seamlessly transfer assets and data between multiple blockchains. Features of Axelar: Universal cross-chain communication: Axelar provides a universal platform that allows two-way communication between different blockchains. Secure and Scalable: Axelar uses a Distributed Validator Network (DVN) to ensure transactions are secure and scalable. Cross-chain asset transfer: Axelar makes it possible to transfer assets between different blockchains, including native tokens, stablecoins, and NFTs. Data interoperability: Axelar allows

What is Ondo Coin? What are the characteristics of Ondo coin? What is Ondo Coin? What are the characteristics of Ondo coin? Mar 06, 2024 pm 08:22 PM

Ondo Coin: A digital currency with unlimited possibilities Ondo Coin is an innovative digital currency based on blockchain technology and aims to become the cornerstone of the future digital economy. It has the following characteristics: High scalability: Ondo coin adopts a unique consensus mechanism and can handle thousands of transactions per second to meet the needs of large-scale applications. Low transaction fees: The transaction fees of Ondo Coin are extremely low, providing users with an affordable transaction experience. Fast confirmation: Ondo coin transaction confirmation time is extremely fast, usually only a few seconds, providing users with an efficient trading experience. Security: Ondo currency uses advanced encryption technology to ensure safe and reliable transactions and protect user assets. Eco-friendly: Ondo coin’s consensus mechanism adopts Proof of Stake (PoS), which is better than Proof of Work (P

What is Manta Coin? What are the characteristics of Manta Coin? What is Manta Coin? What are the characteristics of Manta Coin? Mar 06, 2024 pm 10:50 PM

Manta Coin: A privacy-protecting decentralized financial tool Manta Coin (MANTA) is a privacy-protecting token based on MantaNetwork, aiming to provide a more secure and private transaction environment for decentralized finance (DeFi) users and enhance user interaction. experience. Features: Privacy Protection: Manta Coin utilizes zero-knowledge proof technology to allow users to verify transactions without revealing transaction details. Scalability: MantaNetwork uses sharding technology to improve transaction throughput and scalability. Cross-chain interoperability: Manta Coin supports transactions across multiple blockchains, including Ethereum, Polkadot, and Kusama. Decentralization: MantaNetwork is managed by a distributed network of nodes

See all articles