mysql使用navicat编写调用存储过程

Posted 懒惰虫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql使用navicat编写调用存储过程相关的知识,希望对你有一定的参考价值。

在Navicat里面,找到函数,右键,新建函数,选择过程,如果有参数就填写函数,如果没有就直接点击完成

在BEGIN......END中间编写要执行的sql语句,例如下面存储过程取名为pro_data_bak:

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里面引用

<mapper namespace="com.ra.truck.mapper.DataBakMapper">
	<select id="callProcedureOfDataBak">
		{call pro_data_bak()}
	</select>
</mapper>

通过java定时调度调用这个存储过程就OK了

以上是关于mysql使用navicat编写调用存储过程的主要内容,如果未能解决你的问题,请参考以下文章

用navicat工具创建MySQL存储过程

MySQL存储过程和自定义函数Navicat for mysql创建存储过程和函数调用存储过程和函数的区别

navicat for MySQL中的 查询编辑器中如何执行存储过程?

navicat 8.0 mysql中如何调用存储过程

Navicat 创建mysql存过定时执行存过

图解使用Navicat for MySQL创建存储过程