【问题标题】:MySQL: How to insert the result of stored procedure into temporary tableMySQL:如何将存储过程的结果插入临时表
【发布时间】:2013-08-06 05:27:54
【问题描述】:

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

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

INSERT NEWBalance call SP VenAccNo,PeopleId;

但这会产生错误:

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

有没有办法做到这一点?

【问题讨论】:

    标签: mysql stored-procedures


    【解决方案1】:

    不幸的是,你仍然不能在 MySql 中这样做。

    一种可能的解决方案是修改您的 SP 并将其插入到临时表中。

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

    那你的流程是这样的

    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;
    

    【讨论】:

      猜你喜欢
      • 2020-01-26
      • 2018-07-05
      • 1970-01-01
      • 2018-11-16
      • 2020-12-05
      • 1970-01-01
      • 2021-01-10
      • 2012-05-30
      相关资源
      最近更新 更多