今天写了一存储过程,执行过程后,查看目标表数据,有一字段居然显示乱码,经过修改,数据显示正常
存储过程代码如下:
-
DELIMITER $$
-
-
DROP PROCEDURE IF EXISTS `p_ap_heart_down_warning`$$
-
-
CREATE PROCEDURE `p_ap_heart_down_warning`()
-
BEGIN
-
TRUNCATE TABLE ap_heart_down_data_stat;
-
INSERT INTO ap_heart_down_data_stat
-
SELECT
-
'心跳下线',
-
ap_id,
-
systime,
-
SYSDATE()
-
FROM
-
report_ap_heart
-
WHERE systime < SUBDATE(SYSDATE(), INTERVAL 10 MINUTE)
-
AND systime >= SUBDATE(SYSDATE(), INTERVAL 3 HOUR)
-
AND ymd = CURDATE() ;
-
-
IF HOUR(CURTIME())<3 THEN
-
INSERT INTO ap_heart_down_data_stat
-
SELECT
-
'心跳下线',
-
ap_id,
-
systime,
-
SYSDATE()
-
FROM
-
report_ap_heart
-
WHERE systime < SUBDATE(SYSDATE(), INTERVAL 10 MINUTE)
-
AND systime >= SUBDATE(SYSDATE(), INTERVAL 3 HOUR)
-
AND ymd = SUBDATE(CURDATE(),1)
-
AND ap_id NOT IN (SELECT ap_id FROM ap_heart_down_data_stat);
-
END IF;
-
END$$
-
-
DELIMITER ;
目标表建表语句如下:
SHOW CREATE TABLE `ap_heart_down_data_stat`
-
CREATE TABLE `ap_heart_down_data_stat` (
-
`warn_type` VARCHAR(20) DEFAULT NULL COMMENT '告警类型',
-
`ap_id` VARCHAR(12) DEFAULT NULL COMMENT '网关MAC地址',
-
`failover_time` DATETIME DEFAULT NULL COMMENT '设备故障时间',
-
`warn_time` DATETIME DEFAULT NULL COMMENT '报警时间'
-
) ENGINE=INNODB DEFAULT CHARSET=latin1 COMMENT='心跳故障统计表'
执行过程:
-
CALL p_ap_heart_down_warning
查看表数据
SELECT * FROM `ap_heart_down_data_stat`;
-----------------------------------------------------------------------------------------
"warn_type" "ap_id" "failover_time" "warn_time"
"????" "28224600040E" "2015-05-08 12:59:26" "2015-05-08 15:13:14"
"????" "2822460006EA" "2015-05-08 13:59:47" "2015-05-08 15:13:14"
"????" "28224600092C" "2015-05-08 12:13:23" "2015-05-08 15:13:14"
"????" "282246000E3C" "2015-05-08 14:05:53" "2015-05-08 15:13:14"
"????" "282246000E62" "2015-05-08 14:31:47" "2015-05-08 15:13:14"
"????" "282246000ED2" "2015-05-08 13:46:05" "2015-05-08 15:13:14"
"????" "282246000F5A" "2015-05-08 12:28:38" "2015-05-08 15:13:14"
"????" "282246000FC8" "2015-05-08 14:19:20" "2015-05-08 15:13:14"
"????" "282246001194" "2015-05-08 13:23:50" "2015-05-08 15:13:14"
1.客户端界面修改表字符集将latin1改为utf8后,查询结果还是同上 -- 宣告实验失败
2.重新执行过程将原来的数据truncate掉后重新插入,
查询结果还是同上 -- 宣告实验失败
3.drop table
ap_heart_down_data_stat;
建表指定字符集为utf8
-
CREATE TABLE `ap_heart_down_data_stat` (
-
`warn_type` VARCHAR(20) DEFAULT NULL COMMENT '告警类型',
-
`ap_id` VARCHAR(12) DEFAULT NULL COMMENT '网关MAC地址',
-
`failover_time` DATETIME DEFAULT NULL COMMENT '设备故障时间',
-
`warn_time` DATETIME DEFAULT NULL COMMENT '报警时间'
-
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='心跳故障统计表'
重新执行过程后查看表数据
select * from
ap_heart_down_data_stat;
------------------------------------------------------------------------------------------
"warn_type" "ap_id" "failover_time" "warn_time"
"心跳下线" "28224600040E" "2015-05-08 12:59:26" "2015-05-08 15:13:14"
"心跳下线" "2822460006EA" "2015-05-08 13:59:47" "2015-05-08 15:13:14"
"心跳下线" "28224600092C" "2015-05-08 12:13:23" "2015-05-08 15:13:14"
"心跳下线" "282246000E3C" "2015-05-08 14:05:53" "2015-05-08 15:13:14"
"心跳下线" "282246000E62" "2015-05-08 14:31:47" "2015-05-08 15:13:14"
"心跳下线" "282246000ED2" "2015-05-08 13:46:05" "2015-05-08 15:13:14"
"心跳下线" "282246000F5A" "2015-05-08 12:28:38" "2015-05-08 15:13:14"
"心跳下线" "282246000FC8" "2015-05-08 14:19:20" "2015-05-08 15:13:14"
"心跳下线" "282246001194" "2015-05-08 13:23:50" "2015-05-08 15:13:14"
warn_type列数据显示正常。
阅读(2022) | 评论(0) | 转发(0) |