MySql 从存储过程中调用存储函数导致错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4055434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:35:06  来源:igfitidea点击:

MySql calling stored function from within a stored procedure causing error

sqlmysqlstored-proceduresmysql-error-1064stored-functions

提问by Ronedog

I'm getting a 1064 error when trying to call a stored function from within a stored procedure. It only happens on the line where I try to do this: SET account_id = get_account_id(user);. What is the problem and how can I fix it?

尝试从存储过程中调用存储函数时出现 1064 错误。它只是发生在那里我尝试做这行:SET account_id = get_account_id(user);。有什么问题,我该如何解决?

Account ID Stored Functions:

账户 ID 存储功能:

CREATE DEFINER=`aaron`@`%` FUNCTION `get_account_id`(user VARCHAR(255)) RETURNS int(11)
BEGIN
    DECLARE xaccount_id INT DEFAULT 0;

   #Get Account ID and place into variable used when calling stored procedure that builds the tree structure for the leaf node portfolio id
    SELECT account_id
    FROM rst_sessions.session_data
    WHERE  username = user
    ORDER BY update_date DESC LIMIT 1
    INTO xaccount_id;

    RETURN xaccount_id;
END

Stored Procedure that is trying to call the stored Function:

试图调用存储函数的存储过程:

CREATE DEFINER=`aaron`@`%` PROCEDURE `build_report_portfolio_list`(user VARCHAR(255))
    READS SQL DATA
BEGIN

    DECLARE portf_id INT;
    DECLARE portf_name VARCHAR(255);
    DECLARE str_portf_parent_list VARCHAR(455);
    DECLARE done INT DEFAULT 0;
  DECLARE account_id INT;

  SET account_id = get_account_id(user);
END

回答by Ronedog

I don't even know if it was possible what I was trying to do, which may have caused the error. But I found a work around by calling the SF as a parameter with the call to the SP and got it to do what I needed it to do.

我什至不知道我试图做的事情是否可能,这可能导致了错误。但是我找到了一种解决方法,通过调用 SF 作为参数调用 SP 并让它做我需要它做的事情。

Code is: CALL build_report_portfolio_list(get_account_id('username_here'));

代码是: CALL build_report_portfolio_list(get_account_id('username_here'));