我正在使用MySQL Workbench 5.7
我有下表创建和存储过程:
DROP TABLE MV_SALESBYMONTH;
CREATE TABLE MV_SALESBYMONTH
(
`time_year` int, `time_month` int, `prod_code` int,`sale_units` int, `sale_price` int);
DELIMITER $$
CREATE procedure `REFRESH_MV_SALESBYMONTH` () BEGIN
TRUNCATE TABLE `MV_SALESBYMONTH`;
INSERT INTO MV_SALESBYMONTH
(SELECT TIME_YEAR AS 'YEAR', TIME_MONTH AS 'MONTH', PROD_CODE AS 'PRODUCT',
SUM(SALE_UNITS) AS 'UNITS SOLD', SUM(SALE_UNITS*SALE_PRICE) AS 'SALES TOTAL'
FROM TIME T, SALES S
WHERE S.TIME_ID = T.TIME_ID
GROUP BY TIME_YEAR, TIME_MONTH, PROD_CODE);
END $$
DELIMITER ;
第5步:使用物化视图
CALL REFRESH_MV_SALESBYMONTH();
SELECT * FROM MV_SALESBYMONTH;
当我尝试运行语句时:
CALL REFRESH_MV_SALESBYMONTH();
我收到错误1265:数据截断列' prod_code'在第7行
答案 0 :(得分:0)
在create table语句中将prod_code定义为varchar(100)。这样它可以保存源数据中可能的最大字符数。