MySQL:如何将存储过程的结果插入临时表

SHI*_*A73 4 mysql stored-procedures

我想将存储过程的结果插入临时表,如下所示:

CREATE temporary TABLE NEWBalance (VendorAmount NUMERIC(15,2),   
                                   UserBalanceAmount NUMERIC(15,2));  

INSERT NEWBalance call SP VenAccNo,PeopleId;
Run Code Online (Sandbox Code Playgroud)

但这会产生错误:

Error Code: 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 'call SP VenAccNo,PeopleId' at line 1
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

pet*_*erm 6

不幸的是你仍然无法在MySql中做到这一点.

一种可能的解决方案是修改您的SP并使其插入临时表.

CREATE PROCEDURE your_sp(...)
BEGIN
    -- do your processing
    ...
    -- insert results into a temporary table
    INSERT INTO NEWBalance ...
    SELECT ...;
END
Run Code Online (Sandbox Code Playgroud)

然后你的流程是这样的

CREATE temporary TABLE NEWBalance 
(
 VendorAmount NUMERIC(15,2),
 UserBalanceAmount NUMERIC(15,2)
);

CALL your_sp (...);

-- do your processing on data in a temporary table
...

DROP TEMPORARY TABLE NEWBalance;
Run Code Online (Sandbox Code Playgroud)