2010-09-06 47 views
0

嗨,我是新來mysql.here我寫了錯誤發生的過程:錯誤代碼:1324未定義CURSOR:OPEN

DELIMITER $$ 

USE `flower2`$$ 

DROP PROCEDURE IF EXISTS `test`$$ 

CREATE PROCEDURE `test`() 

BEGIN 

DECLARE soldcount INT; 

DECLARE goodsid INT; 

DECLARE not_found INT; 

DECLARE curGoodsId CURSOR FOR SELECT goods_id FROM ecs_order_goods; 

DECLARE curSoldCount CURSOR FOR SELECT sold_count FROM ecs_goods; 

DECLARE CONTINUE HANDLER FOR NOT FOUND SET not_found = 1; 

DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; 

START TRANSACTION; 

OPEN curGoodsId; 

OPEN OPEN curSoldCount; 

WHILE not_found = 0 DO 

FETCH curSoldCount INTO soldcount; 

FETCH curGoodsId INTO goodsid; 

    SELECT COUNT(goods_id) FROM ecs_order_goods INTO soldcount; 

    UPDATE ecs_goods SET sold_count=soldcount WHERE goods_id=goodsid; 

IF NOT not_found THEN 

    SET not_found = 0 ; 

END IF; 

END WHILE; 

CLOSE curGoodsId; 

CLOSE curSoldCount; 

COMMIT; 

END$$ 

DELIMITER ; 

錯誤消息:

(0 row(s) affected) 
Execution Time : 00:00:00:000 
Transfer Time : 00:00:00:015 
Total Time  : 00:00:00:015 

(0 row(s) affected) 
Execution Time : 00:00:00:000 
Transfer Time : 00:00:01:141 
Total Time  : 00:00:01:141 

Query : **CREATE PROCEDURE `test`() BEGIN DECLARE soldcount INT; DECLARE goodsid int; DECLARE not_found INT; DECLARE curGoodsId CURSOR ... 
Error Code : 1324 
Undefined CURSOR: OPEN** 
Execution Time : 00:00:00:000 
Transfer Time : 00:00:00:000 
Total Time  : 00:00:00:000 

回答

1

你寫

OPEN OPEN curSoldCount; 

嘗試

OPEN curSoldCount; 
OMG!
+0

OMG!謝謝。花花公子.. – tunpishuang 2010-09-06 09:53:45