我写了一个商店程序,我在解析时遇到错误:
消息102,级别15,状态1,过程CleanLog,第9行不正确 语法附近' LOOP'。 Msg 102,Level 15,State 1,Procedure CleanLog, 第28行' LOOP'附近的语法不正确。
我正在使用Microsoft SQL Server Management Studio 10.50.1600.1。任何帮助表示赞赏。
CREATE PROCEDURE dbo.CleanLog
AS
BEGIN
DECLARE @DATE_VALUE CHAR(16);
DECLARE DISTINCT_DATE_CUR CURSOR FOR SELECT DISTINCT(CAST(INSERT_DATE AS DATE)) AS INSERT_DATE FROM RECORD_TABLE ORDER BY INSERT_DATE;
OPEN DISTINCT_DATE_CUR;
read_loop: LOOP
FETCH DISTINCT_DATE_CUR INTO @DATE_VALUE;
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE FROM RECORD_TABLE WHERE CAST(INSERT_DATE AS DATE) = @DATE_VALUE;
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
END
END LOOP;
CLOSE DISTINCT_DATE_CUR;
END