我试着这样做
CREATE FUNCTION getOneCentOrderIds (s text) RETURNS text
BEGIN
DECLARE no_more_orders, ent_id INT default 0;
DECLARE ids text;
DECLARE orders_cur CURSOR FOR SELECT entity_id FROM sales_flat_order WHERE total_due = 0.01;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_orders = 1;
OPEN orders_cur;
FETCH NEXT FROM orders_cur INTO ent_id;
REPEAT
SET ids = CONCAT(ids, ', ', ent_id);
FETCH orders_cur INTO ent_id;
UNTIL no_more_orders END REPEAT;
CLOSE orders_cur;
RETURN ids;
END$
但是当我执行该函数时我得到空值。
如果我只是删除 concat 并离开,SET ids = ent_id
我会得到光标中的最后一个 id,如预期的那样。
我应该如何进行连接?