1

次のストアドプロシージャを使用して、日付ディメンションを入力しています。そしてそれは次のエラーを与えています

#1064-SQL構文にエラーがあります。MySQLサーバーのバージョンに対応するマニュアルで、6行目の「DELETEFROM Date_Dim SET v_full_date = p_start_date WHILEv_full_date<p_end_d」の近くで使用する正しい構文を確認してください。

CREATE PROCEDURE datedimbuild (p_start_date DATE, p_end_date DATE)

BEGIN

DECLARE v_full_date DATE
DELETE FROM Date_Dim
SET v_full_date = p_start_date

WHILE v_full_date < p_end_date 
DO
 INSERT INTO Date_Dim 
(
            Full_Date ,
            DayOfMonth ,
            DayOfYear ,
            DayOfWeek ,
            Day_Name ,
            Month_Number,
            Month_Name,
            Year,
            Quarter
  )
 VALUES 
(
            v_full_date,
            DAYOFMONTH(v_full_date),
            DAYOFYEAR(v_full_date),
            DAYOFWEEK(v_full_date),
            DAYNAME(v_full_date),
            MONTH(v_full_date),
            MONTHNAME(v_full_date),
            YEAR(v_full_date),
            QUARTER(v_full_date)
   );

SET v_full_date = DATE_ADD(v_full_date, INTERVAL 1 DAY)

END WHILE
END
4

2 に答える 2

1

ステートメントを区切る必要があります。これを試して:

DELIMITER $$

CREATE PROCEDURE datedimbuild (p_start_date DATE, p_end_date DATE)

BEGIN

DECLARE v_full_date DATE;
DELETE FROM Date_Dim;
SET v_full_date = p_start_date;

WHILE v_full_date < p_end_date 
DO
 INSERT INTO Date_Dim 
(
            Full_Date ,
            DayOfMonth ,
            DayOfYear ,
            DayOfWeek ,
            Day_Name ,
            Month_Number,
            Month_Name,
            Year,
            Quarter
  )
 VALUES 
(
            v_full_date,
            DAYOFMONTH(v_full_date),
            DAYOFYEAR(v_full_date),
            DAYOFWEEK(v_full_date),
            DAYNAME(v_full_date),
            MONTH(v_full_date),
            MONTHNAME(v_full_date),
            YEAR(v_full_date),
            QUARTER(v_full_date)
   );

SET v_full_date = DATE_ADD(v_full_date, INTERVAL 1 DAY);

END WHILE;
END $$

DELIMITER ;
于 2013-02-07T06:46:34.117 に答える
0

使用する

DELIMITER |

CREATE PROCEDURE datedimbuild (p_start_date DATE, p_end_date DATE)

BEGIN

DECLARE v_full_date DATE;
DELETE FROM Date_Dim;
SET v_full_date = p_start_date;

WHILE v_full_date < p_end_date 
DO
 INSERT INTO Date_Dim 
(
            Full_Date ,
            DayOfMonth ,
            DayOfYear ,
            DayOfWeek ,
            Day_Name ,
            Month_Number,
            Month_Name,
            Year,
            Quarter
  )
 VALUES 
(
            v_full_date,
            DAYOFMONTH(v_full_date),
            DAYOFYEAR(v_full_date),
            DAYOFWEEK(v_full_date),
            DAYNAME(v_full_date),
            MONTH(v_full_date),
            MONTHNAME(v_full_date),
            YEAR(v_full_date),
            QUARTER(v_full_date)
   );

SET v_full_date = DATE_ADD(v_full_date, INTERVAL 1 DAY);

END WHILE;
END;
|
于 2013-02-07T06:47:42.663 に答える