备份数据分为两步事务控制:批量插入和删除
插入sql:
public static final String SQL_BACKUP_DAILY_HISTORY_FORECAST_RESULT = "insert into sf_daily_fc_sales_bak(id,pm_info_id,merchant_id,product_id,category_id,fc_avg_price,page_price,fc_sales,real_sales,fc_effect,fc_except_type,create_time,stat_date,avg_his_sales,del_error_flag,pgm_code,model_id,forecast_date,event,is_oos,fc_sales_normal) " + "select seq_sf_daily_fc_sales.nextval,pm_info_id,merchant_id,product_id,category_id,fc_avg_price,page_price,fc_sales,real_sales,fc_effect,fc_except_type,create_time,stat_date,avg_his_sales,del_error_flag,pgm_code,model_id,forecast_date,event,is_oos,fc_sales_normal from sf_daily_fc_sales where sf_daily_fc_sales.forecast_date <:backupHistoryDate";
犯过一个很低级的错误,找了半天原因,org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLExce和缺少索引参数index ::1啥的错误~ ~ ~ ~
关键点就在于我的sql里面参数前面的冒号跟参数间多了个空格!!!: backupHistoryDate,真是大错特错。。。
注:select seq_sf_daily_fc_sales.nextval的话备份后的id和查出的id不同,是自动生成的序列中的id,select id的话就和查出的id相同。
删除sql:
public static final String SQL_DELETE_DAILY_HISTORY_FORECAST_RESULT = "delete from sf_daily_fc_sales where forecast_date < :backupHistoryDate";
细心编码,进步每一天~