raddacct& amp; Table Schame 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. */
答案 0 :(得分:0)
看起来您没有更改DELIMITER
使用多个语句要求客户端能够发送 声明字符串包含;声明分隔符。在mysql中 命令行客户端,使用分隔符命令处理。 改变;语句结束分隔符(例如,//)允许 ;在程序体中使用。
在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 演示