2012-09-20 45 views
1

我建立以下存儲過程獲取的結果從一個函數:在MySQL

DELIMITER $$ 
DROP PROCEDURE IF EXISTS update_alert_system$$ 
CREATE PROCEDURE update_alert_system() 
BEGIN 

DECLARE done INT; 
DECLARE link_id_var INT; 
DECLARE curl CURSOR FOR SELECT link_id FROM alert_system; 

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; 

OPEN curl; 
my_loop:LOOP 
FETCH curl INTO link_id_var; 

call ignore_check(link_id_var); 
call snooze_check(link_id_var); 

IF done=1 THEN 
LEAVE my_loop; 
END IF; 

END LOOP my_loop 

END$$ 
DELIMITER ; 

的問題是我獲取數據,並把把作爲參數傳遞給兩個函數的方式:

call ignore_check(link_id_var); 
call snooze_check(link_id_var); 

這兩個函數都應該返回一個數字。這種功能的例子。

DELIMITER $$ 
DROP FUNCTION IF EXISTS snooze_check $$ 
CREATE FUNCTION snooze_check(link_id_in INT) 
RETURNS INT READS SQL DATA 
RETURN (SELECT count(*) as SUCCESSES FROM link_results WHERE link_id=link_id_in AND 

Length(anchor_match)>1); 
DELIMITER ; 

的問題是如何從打盹檢查功能返回值,並將其設置爲可變在我的存儲過程

回答

0
DECLARE Result_ignore_check INT; 
SET Result_ignore_check=ignore_check(link_id_var); 
+0

野趣感謝.. –