0

raddacct 和 radacctold 的表结构(两者结构相同,只是引擎不同)

CREATE TABLE `radacctold` (
  `RadAcctId` bigint(21) NOT NULL,
  `AcctSessionId` varchar(128) default NULL,
  `AcctUniqueId` varchar(32) NOT NULL default '',
  `UserName` varchar(64) NOT NULL default '',
  `Realm` varchar(64) default '',
  `NASIPAddress` varchar(15) NOT NULL default '',
  `NASPortId` int(12) default NULL,
  `NASPortType` varchar(32) default NULL,
  `AcctStartTime` datetime NOT NULL default '0000-00-00 00:00:00',
  `AcctStopTime` datetime NOT NULL default '0000-00-00 00:00:00',
  `AcctSessionTime` int(12) default NULL,
  `AcctAuthentic` varchar(32) default NULL,
  `ConnectInfo_start` varchar(32) default NULL,
  `ConnectInfo_stop` varchar(32) default NULL,
  `AcctInputOctets` int(12) unsigned default NULL,
  `AcctOutputOctets` bigint(12) default NULL,
  `CalledStationId` varchar(50) NOT NULL default '',
  `CallingStationId` varchar(50) NOT NULL default '',
  `AcctTerminateCause` varchar(32) NOT NULL default '',
  `ServiceType` varchar(32) default NULL,
  `FramedProtocol` varchar(32) default NULL,
  `FramedIPAddress` varchar(15) NOT NULL default '',
  `AcctStartDelay` int(12) default NULL,
  `AcctStopDelay` int(12) default NULL
) ENGINE = ARCHIVE;


CREATE PROCEDURE radius.archive_acct()
BEGIN
  INSERT INTO radacctold
    SELECT * FROM radacct
    WHERE acctstoptime > 0
    AND date(acctstarttime) < (CURDATE() - INTERVAL 3 MONTH);
  DELETE FROM radacct
    WHERE acctstoptime > 0
    AND date(acctstarttime) < (CURDATE() - INTERVAL 3 MONTH);
END

it return with error
CREATE PROCEDURE radius.archive_acct()
BEGIN
  INSERT INTO radacctold
    SELECT * FROM radacct
    WHERE acctstoptime > 0
    AND date(acctstarttime) < (CURDATE() - INTERVAL 3 MONTH);

/* SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6 */
/* Affected rows: 0  Found rows: 0  Warnings: 0  Duration for 0 of 3 queries: 0.000 sec. */
4

1 回答 1

0

您似乎没有更改DELIMITER

使用多个语句要求客户端能够发送包含 ; 的语句字符串。语句分隔符。在 mysql 命令行客户端中,这是使用delimiter命令处理的。改变; 语句结束分隔符(例如,到 //) permit ; 在程序主体中使用。

在 MySql 客户端中,您应该像这样定义您的过程

DELIMITER $$
CREATE PROCEDURE archive_acct()
BEGIN
  INSERT INTO radacctold
  SELECT * 
    FROM radacct
   WHERE acctstoptime > 0
     AND DATE(acctstarttime) < CURDATE() - INTERVAL 3 MONTH;
  DELETE 
    FROM radacct
   WHERE acctstoptime > 0
     AND DATE(acctstarttime) < CURDATE() - INTERVAL 3 MONTH;
END$$
DELIMITER ;

除此之外,您的程序编译时没有其他语法错误。

这是SQLFiddle演示

于 2013-08-05T04:11:58.123 回答