【问题标题】:Mysql stored procedure giving error at runtimeMysql存储过程在运行时出错
【发布时间】:2010-06-29 05:25:17
【问题描述】:

我在Mysql中创建了一个存储过程,如下:

delimiter $$
drop procedure if exists test9$$
Create procedure test9(test_type varchar(20))
Reads sql data
begin

    Declare 1_id int;
    Declare 1_date varchar(20);
    Declare done int default 0;
    Declare cur1 cursor for 
        select id,name from buyers where ticket_type='test_type';
    Declare Continue handler for not found set done=1;

    Create temporary table if not exists ticketninja.history2(n_id int,n_date varchar(20));

    Open cur1;
        hist_loop:loop
            fetch cur1 into 1_id,1_date;

                if done=1 then
                    leave hist_loop;
                end if;

        insert into ticketninja.history2(n_id ,n_date) values(1_id,1_date);
        End loop hist_loop;
    close cur1;

    select * from history2;
    drop table history2;

End;

$$

delimiter ;

但是当我使用它来调用它时,

call test9('platinum');

它返回一个错误说:

#1312 - PROCEDURE ticketninja.test1 can't return 
a result set in the given context

我在这里做错了什么?

【问题讨论】:

    标签: mysql stored-procedures mysql-error-1312


    【解决方案1】:

    我认为您需要一个 OUT 变量(参见第一个代码示例 here)

    【讨论】:

    • 即使 OUT 变量不起作用,我已按以下方式进行了更改:创建过程 test9(out test_type varchar(20))
    猜你喜欢
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    相关资源
    最近更新 更多