下面是在mysql 查询浏览器里写存储过程和调试,步子为:在数据库上右键选择create new procedure /
function,输入一个名称,我这里输入的是"bbb",它会自动创建一个空的过程模板,我声明了三个变量,给三个变量赋值,并输出三个变量,在查询
浏览器菜单 tools -> mysql command line client 直接进DOS窗口,先use
databasename;call procedurename();可以带参数,我这里没用参数。
----------------------------------------------------------------------------------------------------------
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`bbb`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`.`bbb`()
BEGIN
declare a int;
declare b varchar(45);
declare c varchar(45);
set a = 3;
set b = "abc";
select strname from t1 into c;
select a;
select b;
select c;
END $$
DELIMITER ;
------------------------------------------------------------------------------------------------------------
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.1.30-community MySQL Community Server (GPL)
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> use test;
Database changed
mysql> call bbb();
+------+
| a |
+------+
| 3 |
+------+
1 row in set (0.02 sec)
+------+
| b |
+------+
| abc |
+------+
1 row in set (0.03 sec)
+-------------+
| c |
+-------------+
| test string |
+-------------+
1 row in set (0.03 sec)
Query OK, 0 rows affected (0.05 sec)
mysql>
-------------------------------------------------------------------------------------------------------
感觉csdn还没有百度专业,在那里可以贴抓图,我在百度也有博客一般都附了抓图
----------------------------------------------------------------------------------------------------------
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`bbb`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`.`bbb`()
BEGIN
declare a int;
declare b varchar(45);
declare c varchar(45);
set a = 3;
set b = "abc";
select strname from t1 into c;
select a;
select b;
select c;
END $$
DELIMITER ;
------------------------------------------------------------------------------------------------------------
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.1.30-community MySQL Community Server (GPL)
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> use test;
Database changed
mysql> call bbb();
+------+
| a |
+------+
| 3 |
+------+
1 row in set (0.02 sec)
+------+
| b |
+------+
| abc |
+------+
1 row in set (0.03 sec)
+-------------+
| c |
+-------------+
| test string |
+-------------+
1 row in set (0.03 sec)
Query OK, 0 rows affected (0.05 sec)
mysql>
-------------------------------------------------------------------------------------------------------
感觉csdn还没有百度专业,在那里可以贴抓图,我在百度也有博客一般都附了抓图
本文介绍如何在MySQL中创建并调试存储过程。通过实例演示了在MySQL查询浏览器中创建名为“bbb”的存储过程,包括变量声明、赋值及查询操作。

被折叠的 条评论
为什么被折叠?



