-- 设置数据库的结束符为 ///
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
原文地址:http://blog.51cto.com/13480443/2107170