mysql使用存储过程怎样对另外一个mysql操作
1个回答
展开全部
你创建一个存储过程C
先执行存储过程A,并得到返回值
再判断返回值执行存储过程B
例如:
mysql> \d //
mysql> create procedure test(v_name char(20),out v_id int)
-> BEGIN
-> SELECT id into v_id from t1 WHERE name=v_name;
-> END;
-> //
mysql> create procedure test1(v_id int,out v_name char(20))
-> BEGIN
-> SELECT name into v_name from t2 where id=v_id;
-> END;
-> //
mysql> create procedure test2(inout v_name char(20))
-> BEGIN
-> DECLARE v_id int;
-> CALL test(v_name,v_id);
-> CALL test1(v_id,v_name);
-> END;
-> //
mysql> set @aa='xx‘//
Query OK, 0 rows affected (0.00 sec)
mysql> call test2(@aa) //
Query OK, 0 rows affected (0.01 sec)
mysql> select @aa//
+------+
| @aa |
+------+
| x2 |
+------+
1 row in set (0.00 sec)
先执行存储过程A,并得到返回值
再判断返回值执行存储过程B
例如:
mysql> \d //
mysql> create procedure test(v_name char(20),out v_id int)
-> BEGIN
-> SELECT id into v_id from t1 WHERE name=v_name;
-> END;
-> //
mysql> create procedure test1(v_id int,out v_name char(20))
-> BEGIN
-> SELECT name into v_name from t2 where id=v_id;
-> END;
-> //
mysql> create procedure test2(inout v_name char(20))
-> BEGIN
-> DECLARE v_id int;
-> CALL test(v_name,v_id);
-> CALL test1(v_id,v_name);
-> END;
-> //
mysql> set @aa='xx‘//
Query OK, 0 rows affected (0.00 sec)
mysql> call test2(@aa) //
Query OK, 0 rows affected (0.01 sec)
mysql> select @aa//
+------+
| @aa |
+------+
| x2 |
+------+
1 row in set (0.00 sec)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询