MySQL Forums
Forum List  »  Stored Procedures

CONCAT not working
Posted by: David Villalobos Cambronero
Date: February 02, 2012 08:54AM

Hi,

I have the following procedure, there is a variable called sDestinatarios, inside of it I concatenate some some other values, but in the time of showing it is empty (NULL).

My question is: what I'm doing wrong?

Best regards
David

delimiter |

DROP PROCEDURE IF EXISTS `PruebaMercadeo` |
CREATE PROCEDURE `PruebaMercadeo`()
LANGUAGE SQL
DETERMINISTIC
SQL SECURITY DEFINER
MODIFIES SQL DATA
COMMENT 'Guarda o modifica datos en la tabla Mercadeo_Envios'
BEGIN

DECLARE `iFinalCursor` TINYINT DEFAULT 0;
DECLARE `sDestinatario` VARCHAR(310);
DECLARE `iClasificacion` SMALLINT UNSIGNED DEFAULT 0;
DECLARE `sDestinatarios` MEDIUMTEXT;
DECLARE `bSalir` BOOL DEFAULT FALSE;
DECLARE `iPosicionInicio` INT DEFAULT 1;
DECLARE `iPosicionFinal` INT DEFAULT 0;

DECLARE `cDestinatarios` CURSOR FOR SELECT User FROM `mysql`.`user`;
DECLARE `cUsers` CURSOR FOR SELECT * FROM `tmpDestinatarios`;

DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET `iFinalCursor` = 1;

DROP TABLE IF EXISTS `tmpDestinatarios`;
CREATE TEMPORARY TABLE `tmpDestinatarios` (`Destinatario` VARCHAR(310) COLLATE utf8_spanish_ci) ENGINE = MEMORY DEFAULT CHARSET = utf8;


OPEN `cDestinatarios`;
CICLOCorreos: LOOP
FETCH `cDestinatarios` INTO `sDestinatario`;
IF `iFinalCursor` = 1 THEN LEAVE CICLOCorreos; END IF;
INSERT INTO `tmpDestinatarios` VALUES (`sDestinatario`);
END LOOP CICLOCorreos;
CLOSE `cDestinatarios`;

SELECT * FROM `tmpDestinatarios`;

SET `iFinalCursor` = 0;
OPEN `cUsers`;
CICLOCorreos: LOOP
FETCH `cUsers` INTO `sDestinatario`;
IF `iFinalCursor` = 1 THEN LEAVE CICLOCorreos; END IF;
SET `sDestinatarios` = CONCAT(`sDestinatarios`, `sDestinatario`);
END LOOP CICLOCorreos;
CLOSE `cUsers`;

SELECT `sDestinatarios`; #Why this is NULL?

END |


DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
CONCAT not working
2705
February 02, 2012 08:54AM
1099
February 03, 2012 09:46AM
871
February 03, 2012 01:34PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.