日期:2014-05-16  浏览次数:21325 次

MYSQL:Commands out of sync; you can't run this command now
昨天请高人帮忙改了个存储过程,也觉得代码已经没问题了,但跑起来总是提示这个错误,头都大了。

存储过程代码如下:
SQL code
 
-- --------------------------------------------
-- Routine DDL
-- --------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`%` PROCEDURE `USP_CreateTrackerLogTable`(IN Pointer DATETIME,IN Counts INT)
begin
declare CountPointer int;
declare DateString varchar(20);
declare TableName varchar(50);
declare SQLTxt varchar(5000);
declare ExecuteSQL varchar(8000);
   
Set CountPointer = Counts;
   
Set SQLTxt = '
CREATE TABLE IF  NOT EXISTS Tracker_Log(
LogID bigint PRIMARY KEY  auto_increment NOT NULL,     /*自增ID*/
TrackerID varchar(50) NOT NULL,             /*日志ID*/
LogTime datetime NOT NULL,                 /*日志时间*/
SessionId varchar(50) NOT NULL,                     /*会话ID*/
PassportID bigint NULL,                     /*账户ID*/
UserID bigint NULL,                     /*用户ID*/
ClientIP varchar(64) NULL,                     /*客户端IP*/
ServerIP varchar(64) NULL,                 /*应用服务器IP*/
CurrentUrl varchar(255) NULL,                 /*当前页链接*/
ReferrerUrl varchar(255) NULL,                 /*前一页链接*/
ClickLinkUrl varchar(255) NULL,                 /*超链接链接地址*/
ClickLinkTitle nvarchar(200) NULL,                 /*超链接链接名*/
CurrentClientTime datetime NULL,                 /*当前客户端时间*/
CurrentServerTime datetime NULL,                 /*当前应用服务器时间*/
ClientServerTimeDif bigint Null,                     /*客户端与服务器时间差*/
ServerExecuteTime bigint NULL,                 /*应用服务器执行请求时间*/
NetTransTime bigint NULL,                     /*网络传输时间*/
ServerResponseTime datetime NULL,             /*服务器输出时时间*/
ClientLoadTime bigint NULL,                 /*客户端页面加载时间*/
UserDwellTime bigint NULL                     /*用户在当前页停留时间*/
);';

WHILE (CountPointer > 0) DO
        BEGIN
/*处理日期*/
            SET DateString = CONCAT(RIGHT(CAST(YEAR(Pointer) AS CHAR(4)), 2),'_',
            RIGHT('0' + CAST(MONTH(Pointer) AS CHAR(2)), 2),'_',
            RIGHT('0' + CAST(DAY(Pointer) AS CHAR(2)), 2));
             
Set TableName = 'Tracker_Log_' + DateString;

/*替换脚本字符串*/
Select ExecuteSQL = Replace(SQLTxt, 'Tracker_Log', TableName);

/*执行*/
            Select SQLTxt;
/*SET @asql=ExecuteSQL;
            PREPARE tt FROM @asql;
    &nb