码迷,mamicode.com
首页 > 数据库 > 详细

mysql-函数,视图

时间:2018-04-24 13:52:58      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:procedure view

存储过程函数

-- 设置数据库的结束符为 ///
mysql> delimiter ///
-- 创建过程函数test
mysql> create procedure test(a int)
    -> begin
    -> select * from student where id=a;
    -> end
    -> ///
Query OK, 0 rows affected (0.01 sec)

mysql> delimiter ;

--调用函数 test
mysql> call test(2);
+----+------+-----+-----+
| id | name | age | sex |
+----+------+-----+-----+
|  2 | lisi |  31 | 0   |
+----+------+-----+-----+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

-- 查看函数 test 的状态信息
mysql> show procedure status like ‘test‘ \G       
*************************** 1. row ***************************
                  Db: shop
                Name: test
                Type: PROCEDURE
             Definer: root@localhost
            Modified: 2018-04-24 12:42:43
             Created: 2018-04-24 12:42:43
       Security_type: DEFINER
             Comment: 
character_set_client: utf8
collation_connection: utf8_general_ci
  Database Collation: utf8_general_ci
1 row in set (0.00 sec)

-- 删除函数 test
mysql> drop procedure test;  

视图

-- 创建视图
mysql> create view test_view(name,age) as select name,age from student where id =5;
Query OK, 0 rows affected (0.00 sec)

-- 视图调用 
mysql> select * from test_view;
+--------+-----+
| name   | age |
+--------+-----+
| tianqi |  42 |
+--------+-----+
1 row in set (0.01 sec)

-- 查看视图的创建过程
mysql> show create view test_view \G

mysql-函数,视图

标签:procedure view

原文地址:http://blog.51cto.com/13480443/2107170

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!