在Navicat裏面,找到函數,右鍵,新建函數,選擇過程,若是有參數就填寫函數,若是沒有就直接點擊完成java
在BEGIN......END中間編寫要執行的sql語句,例以下面存儲過程取名爲pro_data_bak:git
BEGIN /*把rd01_device_callback_data 2天前的數據備份到rd01_device_callback_data_bak*/ insert into rd01_device_callback_data_bak ( id, imei, travelid, gps_time, receive_time, transmit_time, altitude, speed, latitude, longitude, course, pdop, satnum, alarm_type0, alarm_name0, alarm_type1, alarm_name1, alarm_photo_linkurl, startup_time, shudown_time, is_used, create_time, create_by, update_time, update_by )SELECT id id, imei imei, travelid travelId, gps_time gpsTime, receive_time receiveTime, transmit_time transmitTime, altitude altitude, speed speed, latitude latitude, longitude longitude, course course, pdop pdop, satnum satNum, alarm_type0 alarmType0, alarm_name0 alarmName0, alarm_type1 alarmType1, alarm_name1 alarmName1, alarm_photo_linkurl alarmPhotoLinkUrl, startup_time startUpTime, shudown_time shudownTime, is_used isUsed, create_time createTime, create_by createPerson, update_time updateTime, update_by updatePerson FROM rd01_device_callback_data WHERE TO_DAYS(NOW()) - TO_DAYS(create_time) > 1; /*刪除rd01_device_callback_data 2天之前的數據*/ DELETE FROM rd01_device_callback_data WHERE TO_DAYS(NOW()) - TO_DAYS(create_time) > 1; /*把rd02_device_info 2天前的數據備份到rd02_device_info_bak*/ insert into rd02_device_info_bak ( id, message_id, message_property, imei, serial_number, message_split, message_body, media_id, check_code, create_time, create_person, update_time, update_person, is_used )SELECT id id, message_id messageId, message_property messageProperty, imei imei, serial_number serialNumber, message_split messageSplit, message_body messageBody, media_id meidiaId, check_code checkCode, create_time createTime, create_person createPerson, update_time updateTime, update_person updatePerson, is_used isUsed FROM rd02_device_info WHERE TO_DAYS(NOW()) - TO_DAYS(create_time) > 1; /*刪除rd02_device_info 2天前的數據*/ DELETE FROM rd02_device_info WHERE TO_DAYS(NOW()) - TO_DAYS(create_time) > 1; /*把rd_track_info 7天前的數據備份到rd_track_info_bak*/ insert into rd_track_info_bak ( id, license_plate, device_id, address_name, altitude, speed, driving_direction, longitude, latitude, gps, back_time, road_name, road_code, road_level, road_speed_limit, back_seq_no, create_time, del_flag, alarm_type0, alarm_name0, alarm_type1, alarm_name1, alarm_photo_linkurl, gps_time )SELECT id id, license_plate licensePlate, device_id deviceId, address_name addressName, altitude altitude, speed speed, driving_direction drivingDirection, longitude longitude, latitude latitude, gps gps, back_time backTime, road_name roadName, road_code roadCode, road_level roadLevel, road_speed_limit roadSpeedLimit, back_seq_no backSeqNo, create_time createTime, del_flag delFlag, alarm_type0 alarmType0, alarm_name0 alarmName0, alarm_type1 alarmType1, alarm_name1 alarmName1, alarm_photo_linkurl alarmPhotoLinkurl, gps_time gpsTime FROM rd_track_info WHERE TO_DAYS(NOW()) - TO_DAYS(gps_time) > 7; /*刪除rd_track_info 7天前的數據*/ DELETE FROM rd_track_info WHERE TO_DAYS(NOW()) - TO_DAYS(gps_time) > 7; END
而後在xml裏面引用,statementType="CALLABLE"表示調用存儲過程。sql
<mapper namespace="com.ra.truck.mapper.DataBakMapper"> <select id="callProcedureOfDataBak" statementType="CALLABLE"> {call pro_data_bak()} </select> </mapper>
經過java定時調度調用這個存儲過程就OK了app