当前位置: 代码迷 >> MySQL >> MySQL函数进程示例-根据表名和字段删除数据
  详细解决方案

MySQL函数进程示例-根据表名和字段删除数据

热度:309   发布时间:2016-05-05 16:30:19.0
MySQL函数过程示例-根据表名和字段删除数据
[color=brown][size=medium]
BEGIN-- CALL P_DELETE_SERVICE_DATA2('10000','2015-12-23 15:00:00','2015-12-23 15:58:00');SET @index_=1;-- ---------------------------------------------业务数据表-------------------------------------------------------SET @array_tables=CONCAT('WM_INTO_ORDER');                       --  入库单表SET @array_tables=CONCAT(@array_tables,',','WM_INTO_ORDERINFO'); -- 入库单明细表-- ---------------------------------------------业务数据表对应字段------------------------------------------------SET @array_fields=CONCAT('CREATE_TIME');                       --  入库单表      创建时间标识SET @array_fields=CONCAT(@array_fields,',','SJ_OPERATE_TIME'); -- 入库单明细表   上架时间标识-- ---------------------------------------------计算循环次数------------------------------------------------------                        SET @table_count=CHAR_LENGTH(@array_tables)-CHAR_LENGTH(REPLACE(@array_tables,',',''))+1; -- ---------------------------------------------执行业务数据操作--------------------------------------------------WHILE @index_ <= @table_countDO  SET @table_prex=SUBSTRING_INDEX(SUBSTRING_INDEX(@array_tables,',',@index_),',',-1);  SET @table_name=CONCAT(@table_prex,'_',esCorCode);  SET @fieldName=SUBSTRING_INDEX(SUBSTRING_INDEX(@array_fields,',',@index_),',',-1);  SELECT @table_name table_name,@fieldName fieldName;  SET @delete_data=CONCAT('delete from ',@table_name ,' where ',@fieldName,' between ','"',startTime,'"',' and ','"',endTime,'"');  prepare delete_talbe_data from @delete_data;   execute delete_talbe_data;   SET @[email protected]_+1; END WHILE; END
[/size][/color]
  相关解决方案