虽然 Stack Overflow 中有很多关于这个问题的问题,但我无法正确解决,任何人都可以帮助我解决这个问题,假设有两个存储过程,
CREATE PROCEDURE `procOne`(stName varchar(7),fullItemCode varchar(12), fullLedNo varchar(12))
BEGIN
set @x = concat('
SELECT ID, Uprice FROM ',stName,'
where Uprice > 0 and FulItmCode="',fullItemCode,'" and FullLedgerNo = "',fullLedNo,'" order by Dat desc limit 1;
');
PREPARE stmt FROM @x;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
和
CREATE PROCEDURE `prcTwo`()
BEGIN
CREATE TEMPORARY TABLE tmpStore (
ID int(10),
Uprice decimal(18,2)
)
insert into tmpStore exec procOne(@param1, @param2)
select * from tempStore;
DROP TABLE tmpStore;
END
我试过了,但是在尝试保存 prcTwo
ERROR 1064: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'insert into tmpStore exec procOne 'St_BFG','SCI019', 'BIO-JVS-30' output
sele' at line 9 SQL Statement: CREATE DEFINER=user1@localhost PROCEDURE
prcTwo() BEGIN CREATE TEMPORARY TABLE tmpStore ( ID int(10), Uprice
decimal(18,2) ) insert into tmpStore exec procOne 'St_BFG','SCI019',
'BIO-JVS-30' output select * from tempStore; DROP TABLE tmpStore; END
最佳答案
像这样使用输出参数
CREATE PROCEDURE abc(IN id INTEGER, OUT text VARCHAR(255))
BEGIN
SET text = 'asd';
END
你可以这样调用这个过程:
SET @outvar = '';
CALL abc(1, @outvar);
'asd' 将保存在@outvar 中
关于mysql - 如何在mysql中存储存储过程的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9430260/