2
我有這樣的過程:錯誤1064在MySQL存儲過程
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_billing_details`()
BEGIN
DECLARE offsetcount INTEGER DEFAULT 0;
DECLARE totalcount INTEGER DEFAULT 0;
set totalcount = (select count(*) from new.billing);
loopall: LOOP
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE c_subsid varchar(100) DEFAULT "";
DECLARE c_duedate varchar(100) DEFAULT "";
DECLARE c_descriptions varchar(100) DEFAULT "";
DECLARE c_debitamt varchar(100) DEFAULT "";
DECLARE c_transdate varchar(100) DEFAULT "";
DECLARE c_cursor CURSOR FOR
SELECT subsid, descriptions, debitamt, transdate FROM new.billing limit 200 offset offsetcount;
-- declare NOT FOUND handler
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;
OPEN c_cursor;
loopbilling: LOOP
FETCH c_cursor INTO c_subsid, c_descriptions, c_debitamt, c_transdate;
IF v_finished = 1 THEN
LEAVE loopbilling;
END IF;
insert into sakura.customer_bill_items (type ,name, description, amount, created_at) values (if(c_descriptions = "balance", 4, if(c_descriptions = "subscription", 1 , if((c_descriptions like "%modem%" or c_descriptions like "%amplifier%" or c_descriptions like "%power supply%"), 2 , 3))) ,c_descriptions, c_descriptions, c_debitamt, c_transdate);
insert into sakura.customer_monthly_bill_items (customer_id, bill_item_id, start_billing_date) values ((select a.id from sakura.customer a where a.subscriber_id = c_subsid), last_insert_id(), c_transdate);
insert into sakura.customer_billing_details (bill_item_id, subscription_plan_id, bill_item_amount) values (last_insert_id(), (select subscription_plan_id from sakura.customer_subscriptions where customer_id = (select id from sakura.customer where subscriber_id = (select subsid from new.subscriber where subsid = c_subsid))), c_debitamt);
insert into sakura.customer_billing_header (customer_id) select a.id from sakura.customer a where a.subscriber_id = c_subsid;
update sakura.customer_billing_details set header_id = last_insert_id() where id = last_insert_id();
END LOOP loopbilling;
CLOSE c_cursor;
END;
set offsetcount = offsetcount + 200;
IF offsetcount >= totalcount THEN
LEAVE loopall;
END IF;
end LOOP loopall;
END
和它工作正常我的機器上,但是當我嘗試在服務器上運行它,它返回:
ERROR 1064:你的SQL語法有錯誤;檢查手冊 對應於您的MySQL服務器版本的正確語法爲 使用'offsetcount; DECLARE NOT QUANDLER FOR NOT FOUND SET v_finished = 1; OP'31行
我正在使用Workbench 5.5.54,而我們的服務器正在運行5.1.66。我一直在尋找一個小時的答案,但我沒有運氣。希望有人幫助。謝謝!
我真的需要這個偏移量,因爲我運行的記錄過多導致超時,所以我需要按批處理。 –
用變量偏移不起作用,而不是將其更改爲像10這樣的實數,或者任何數字都不是變量。 –
但我需要它來增加,以便它遍歷我的所有數據。我的電腦可以運行它,但我們的服務器不能。我的電腦不是那麼高,所以我需要我們的服務器來完成這項工作。 –