RDS for MySQL 存储过程的创建和查看

  • A+
所属分类:MySQL
高性能企业级服务器首台5折

1. 创建存储过程

可以通过 DMS 或 MySQL 客户端登录到 RDS, 创建存储过程。示例代码如下:

  1. 1
    <span class="pln"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">PROCEDURE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span> </span><code><span class="pln">TEST_PROC</span>

    ;DELIMITER //CREATE PROCEDURE TEST_PROC(IN ID int,OUT NAME VARCHAR(50))BEGINIF(ID = 1) THEN SET NAME = ‘test1’;END IF;IF(ID = 2) THEN SET NAME = ‘test2’;END IF;SELECT version();END //;

2. 查看存储过程

在 RDS for MySQL中,有两种方法查看数据库中的存储过程:
1、通过系统表查询

  1. 1
    <span class="kwd"><span class="hljs-keyword">select</span></span> <span class="pun">*</span> <span class="kwd"><span class="hljs-keyword">from</span></span><span class="pln"> mysql</span><span class="pun">.</span><span class="pln">proc </span><span class="kwd"><span class="hljs-keyword">where</span></span><span class="pln"> db</span><span class="pun">=’</span><span class="pun">‘</span> <span class="kwd"><span class="hljs-keyword">and</span></span><span class="pln"> <span class="hljs-keyword">type</span></span><span class="pun">=’</span><span class="pln"><span class="hljs-keyword">procedure</span></span><span class="pun">’</span><span class="pln"> <span class="hljs-keyword">order</span> </span><span class="kwd"><span class="hljs-keyword">by</span></span><span class="pln"> <span class="hljs-keyword">name</span></span><span class="pun">;</span>

2. 登录到数据库中,执行命令:

  1. 1
    <span class="pln"><span class="hljs-keyword">show</span> <span class="hljs-keyword">procedure</span> <span class="hljs-keyword">status</span></span><span class="pun">;</span><span class="pln"><span class="hljs-keyword">show</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">procedure</span> </span><span class="pln"> \G</span><span class="pun">;</span>

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: