CREATE TEMPORARY TABLE TMP_TEST1 (CUSTOMER_NAME varchar(255));
INSERT INTO TMP_TEST1 (CUSTOMER_NAME) 
VALUES ('JOHN'),('MIKE'),('SMITH');

DELIMITER //
BEGIN NOT ATOMIC

  DECLARE done INT DEFAULT FALSE;
  -- DECLARE CUSTOMER_NAME varchar(255); -- not works
  DECLARE V_CUSTOMER_NAME varchar(255); -- works
  DECLARE CUSTOMER_NAME_LIST text DEFAULT '';
  DECLARE cur1 CURSOR FOR SELECT CUSTOMER_NAME FROM TMP_TEST1;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  
  OPEN cur1;
  read_loop: LOOP
    -- FETCH cur1 INTO CUSTOMER_NAME; -- not works
    FETCH cur1 INTO V_CUSTOMER_NAME; -- works
    IF done THEN
      LEAVE read_loop;
    END IF;
    -- set CUSTOMER_NAME_LIST = CONCAT_WS('|',CUSTOMER_NAME_LIST,CUSTOMER_NAME); -- not works
    set CUSTOMER_NAME_LIST = CONCAT_WS('|',CUSTOMER_NAME_LIST,V_CUSTOMER_NAME); -- works
  END LOOP read_loop;
  CLOSE cur1;

  SELECT CUSTOMER_NAME_LIST;
  
END; //
DELIMITER ;

DROP TEMPORARY TABLE TMP_TEST1;