返回bigint时,函数会抱怨[不允许从函数返回结果集]

时间:2011-11-09 23:58:33

标签: mysql sql database tsql

我忘了把delimiter指令,一些分号和使用tsl语法,如[select variable = field]在mysql中无效。
使用tsl语法时出现mysql错误[不允许从函数返回结果集]并且没有多大帮助 @AndreKR将所有这一切都指向我,谢谢 我使用的是mysqlworkbench 5.2.30 CE。 工作职能变为:

delimiter //
CREATE FUNCTION nextval (seq_name varchar(100))  
  RETURNS bigint(20)  
    READS SQL DATA  
  NOT DETERMINISTIC  
    BEGIN  
     DECLARE workval bigint(20);  
     SELECT count(1) into workval  
        FROM tip_sequence  
        WHERE sequencename = seq_name;  
     IF workval <> 1 THEN  
        DELETE  
            FROM tip_sequence  
            WHERE sequencename = seq_name;  
        INSERT  
            INTO tip_sequence (sequencename, sequenceval, sequencestep)  
            VALUES (seq_name, 1, 1);  
     END IF;
     SELECT sequenceval into workval  
        FROM tip_sequence  
        WHERE sequencename = seq_name;  
     UPDATE tip_sequence  
        SET sequenceval = sequenceval + sequencestep  
        WHERE sequencename = seq_name;  
     RETURN workval;
    END//
delimiter ;

1 个答案:

答案 0 :(得分:1)

我认为SELECT workval = count(1) FROM ...语法无效。我想你的意思是:SELECT count(1) INTO workval FROM ...