同样一个存储过程在windows环境下通过SQLyog调试可以正常运行,但是在linux下同样用SQLyog远程登录运行就出现如下错误:
Error Code : 1243
Unknown prepared statement handler (stmt) given to EXECUTE
系统环境配置:
linux radhat5.5
mysql5.6.2-m5-log
存储过程源码如下:
/*Stored Proc: con_record*/
---------------------------
Create Procedure:
-----------------
CREATE DEFINER=`site`@`localhost` PROCEDURE `con_record`(IN count int(6),
IN recordtime varchar(20),
IN bic varchar(12))
BEGIN
SET @counts = count;
SET @sql = 'select result.agencyBIC as agencybic,';
SET @i = 0;
WHILE @i < @counts
DO
SET @sql = CONCAT(@sql, 'format(sum(result.rtime');
SET @sql = CONCAT(@sql, @i + 1);
SET @sql = CONCAT(@sql, '),0) as time');
SET @sql = CONCAT(@sql, @i + 1);
IF @i != (@counts - 1)
THEN
SET @sql = CONCAT(@sql, ",");
END IF;
SET @i = @i + 1;
END WHILE;
SET @sql = CONCAT(@sql, ' from (select agencyBIC,record_time,');
SET @j = 0;
WHILE @j < @counts
DO
SET @sql = CONCAT(@sql,' CASE HOUR(record_time) WHEN ');
SET @sql = CONCAT(@sql,@j*2);
SET @sql = CONCAT(@sql,' THEN connect ELSE 0 END as rtime');
SET @sql = CONCAT(@sql,@j+1);
IF @j != (@counts - 1)
THEN
SET @sql = CONCAT(@sql, ',');
END IF;
SET @j = @j + 1;
END WHILE;
SET @sql = CONCAT(@sql,' FROM connect_record t where record_time like ? ');
IF LENGTH(bic) > 0
THEN
SET @sql = CONCAT(@sql,'and agencyBIC = ? ');
END IF;
SET @sql = CONCAT(@sql,' ) result group by agencyBIC');
IF LENGTH(recordtime) = 0
THEN
SET @r_time = CONCAT(SUBSTRING(now(),1,10),'%');
ELSE
SET @r_time = CONCAT(SUBSTRING(recordtime,1,10),'%');
END IF;
IF LENGTH(bic) > 0
THEN
EXECUTE stmt USING @r_time,@agencybic;
ELSE
EXECUTE stmt USING @r_time;
END IF;
END
sql_mode:
---------
NO_AUTO_VALUE_ON_ZERO
------解决思路----------------------
在EXECUTE 前要PREPARE
PREPARE stmt FROM @SQL;
EXECUTE stmt;
------解决思路----------------------
mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+------------+
| hypotenuse |
+------------+
| 5 |
+------------+
mysql> DEALLOCATE PREPARE stmt1
可以一起讨论一下mysql 存储过程调用有关问题,欢迎给意见啊~