0

如何进行字符串比较以使用 like 语句检测字符串是否以 12% 或 13% 开头?这个存储过程给了我一个错误,并且使用准备好的语句非常棘手,所以有人可以帮我解决这个问题吗?

    DELIMITER ;;
    CREATE PROCEDURE `insert_trackingtest`(IN deviceid VARCHAR(15),IN timing timestamp,IN valid tinyint(1),IN latitude double,IN longitude double,IN speed double,IN course double,IN power double,IN comando varchar(45))
    BEGIN
        IF deviceid LIKE CONCAT('12','%') OR deviceid LIKE CONCAT('13','%') THEN
            SET @deviceid = CONCAT('0',deviceid);
        ELSE
            SET @deviceid = deviceid;
        END IF;
        SET @query = properprepare('INSERT INTO tracking_? (device_id,time,valid,latitude,longitude,speed,course,power,command) VALUES (?,?,?,?,?,?,?,?,?)',@deviceid);
        PREPARE stmt FROM @query;
        SET @imei = deviceid;
        SET @timing = timing;
        SET @valid = valid;
        SET @latitude = latitude;
        SET @longitude = longitude;
        SET @speed = speed;
        SET @course = course;
        SET @power = power;
        SET @comando = comando;
        EXECUTE stmt USING @deviceid,@timing,@valid,@latitude,@longitude,@speed,@course,@power,@comando;
    END ;;
    DELIMITER ;
4

0 回答 0