MySql объединяет две процедуры в одну (процедуры с курсорами)
Я ищу способ слияния двух процедур в одну, я пытаюсь вставить одну над другой, но не работает, единственное различие между ними - ГДЕ при запросе курсора, спасибо,
Процедура А:
CREATE PROCEDURE nokia_rfid_admin.update_wp_pos_base_pre_finish()
DETERMINISTIC
SQL SECURITY INVOKER
BEGIN
DECLARE tbl_wp_pos_name text DEFAULT "wps_pos_t";
DECLARE done int DEFAULT FALSE;
DECLARE sql_cols_wi text;
DECLARE cur_WP_Version varchar(50) DEFAULT '';
DECLARE cur_DWP_Name varchar(50) DEFAULT '';
DECLARE cur_Col_Origen varchar(50) DEFAULT '';
DECLARE cur_Col_Destino varchar(50) DEFAULT '';
DECLARE el_query text;
DECLARE el_query_value text;
DECLARE el_query_len int;
DECLARE cur_po_xasignacion CURSOR FOR
SELECT
wi_to_po_config.WP_Version,
wi_to_po_config.DWP_Name,
wi_to_po_config.Col_Origen,
wi_to_po_config.Col_Destino
FROM nokia_rfid_admin.wi_to_po_config
WHERE wi_to_po_config.Col_Destino IS NOT NULL AND wi_to_po_config.Process='PreFinish';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET @los_querys = "";
OPEN cur_po_xasignacion;
read_loop_po_xasignacion:
LOOP
FETCH cur_po_xasignacion INTO cur_WP_Version, cur_DWP_Name, cur_Col_Origen, cur_Col_Destino;
IF done THEN
LEAVE read_loop_po_xasignacion;
END IF;
SET sql_cols_wi = NULL;
SET sql_cols_wi = CONCAT(COALESCE(sql_cols_wi, ''),
"UPDATE nokia_rfid.", tbl_wp_pos_name, "
SET ", tbl_wp_pos_name, ".`Fecha_", cur_Col_Destino, "` = ", tbl_wp_pos_name, ".`Fecha_", cur_Col_Origen, "`,
", tbl_wp_pos_name, ".`NumPO_", cur_Col_Destino, "` = ", tbl_wp_pos_name, ".`NumPO_", cur_Col_Origen, "`
WHERE ", tbl_wp_pos_name, ".WP_Version = '", cur_WP_Version, "' AND ",tbl_wp_pos_name, ".Fecha_", cur_Col_Destino, " IS NULL");
IF (cur_DWP_Name IS NOT NULL) THEN
SET sql_cols_wi = CONCAT(COALESCE(sql_cols_wi, ''), " AND ", tbl_wp_pos_name, ".dwp = '", cur_DWP_Name, "';NEWQRY");
ELSE
SET sql_cols_wi = CONCAT(COALESCE(sql_cols_wi, ''), ";NEWQRY");
END IF;
SET @los_querys = CONCAT(COALESCE(@los_querys, ''), sql_cols_wi);
END LOOP read_loop_po_xasignacion;
CLOSE cur_po_xasignacion;
iterator:
LOOP
IF LENGTH(TRIM(@los_querys)) = 0
OR @los_querys IS NULL THEN
LEAVE iterator;
END IF;
SET el_query = SUBSTRING_INDEX(@los_querys, "NEWQRY", 1);
SET el_query_len = LENGTH(el_query);
SET el_query_value = TRIM(el_query);
SET @sql = el_query_value;
PREPARE stmt_exe FROM @sql;
EXECUTE stmt_exe;
SET @los_querys = INSERT(@los_querys, 1, el_query_len + 6, '');
END LOOP;
END
Процедура Б:
CREATE PROCEDURE nokia_rfid_admin.update_wp_pos_base_pre_finish()
DETERMINISTIC
SQL SECURITY INVOKER
BEGIN
DECLARE tbl_wp_pos_name text DEFAULT "wps_pos_t";
DECLARE done int DEFAULT FALSE;
DECLARE sql_cols_wi text;
DECLARE cur_WP_Version varchar(50) DEFAULT '';
DECLARE cur_DWP_Name varchar(50) DEFAULT '';
DECLARE cur_Col_Origen varchar(50) DEFAULT '';
DECLARE cur_Col_Destino varchar(50) DEFAULT '';
DECLARE el_query text;
DECLARE el_query_value text;
DECLARE el_query_len int;
DECLARE cur_po_xasignacion CURSOR FOR
SELECT
wi_to_po_config.WP_Version,
wi_to_po_config.DWP_Name,
wi_to_po_config.Col_Origen,
wi_to_po_config.Col_Destino
FROM nokia_rfid_admin.wi_to_po_config
WHERE wi_to_po_config.Col_Destino IS NOT NULL AND wi_to_po_config.Process='PreFinish';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET @los_querys = "";
OPEN cur_po_xasignacion;
read_loop_po_xasignacion:
LOOP
FETCH cur_po_xasignacion INTO cur_WP_Version, cur_DWP_Name, cur_Col_Origen, cur_Col_Destino;
IF done THEN
LEAVE read_loop_po_xasignacion;
END IF;
SET sql_cols_wi = NULL;
SET sql_cols_wi = CONCAT(COALESCE(sql_cols_wi, ''),
"UPDATE nokia_rfid.", tbl_wp_pos_name, "
SET ", tbl_wp_pos_name, ".`Fecha_", cur_Col_Destino, "` = ", tbl_wp_pos_name, ".`Fecha_", cur_Col_Origen, "`,
", tbl_wp_pos_name, ".`NumPO_", cur_Col_Destino, "` = ", tbl_wp_pos_name, ".`NumPO_", cur_Col_Origen, "`
WHERE ", tbl_wp_pos_name, ".WP_Version = '", cur_WP_Version, "' AND ",tbl_wp_pos_name, ".Fecha_", cur_Col_Destino, " IS NULL");
IF (cur_DWP_Name IS NOT NULL) THEN
SET sql_cols_wi = CONCAT(COALESCE(sql_cols_wi, ''), " AND ", tbl_wp_pos_name, ".dwp = '", cur_DWP_Name, "';NEWQRY");
ELSE
SET sql_cols_wi = CONCAT(COALESCE(sql_cols_wi, ''), ";NEWQRY");
END IF;
SET @los_querys = CONCAT(COALESCE(@los_querys, ''), sql_cols_wi);
END LOOP read_loop_po_xasignacion;
CLOSE cur_po_xasignacion;
iterator:
LOOP
IF LENGTH(TRIM(@los_querys)) = 0
OR @los_querys IS NULL THEN
LEAVE iterator;
END IF;
SET el_query = SUBSTRING_INDEX(@los_querys, "NEWQRY", 1);
SET el_query_len = LENGTH(el_query);
SET el_query_value = TRIM(el_query);
SET @sql = el_query_value;
PREPARE stmt_exe FROM @sql;
EXECUTE stmt_exe;
SET @los_querys = INSERT(@los_querys, 1, el_query_len + 6, '');
END LOOP;
END
После вставки процедуры B курсор этой процедуры не получает строк в инструкции FETCH, но если я запускаю процедуры в независимых процедурах, все работает нормально.