mysql存储过程中调用另一个存储过程需要配置吗
展开全部
mysql存储过程中调用另一个存储过程需要配置吗
你创建一个存储过程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)
你创建一个存储过程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)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询