diff --git a/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql b/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql index 629ce9a5..cb6f98bd 100644 --- a/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql @@ -7,16 +7,18 @@ SQL SECURITY INVOKER BEGIN -- 振り分けスキーマ -DECLARE distribution_schema VARCHAR(64); +DECLARE distribution_schema VARCHAR(20); -- 振り分けカラム -DECLARE target_column_value VARCHAR(64); +DECLARE target_column_value VARCHAR(100); -- 振り分け先テーブルID DECLARE temp_table_id VARCHAR(18); +-- 振り分け先テーブルのSystemModstamp +DECLARE temp_system_modstamp DATETIME; -- カーソルフェッチステータス DECLARE fetch_done BOOLEAN DEFAULT FALSE; -- カーソル設定 -DECLARE table_cursor CURSOR FOR SELECT Id, medaca_parent_msj_product_classification__c FROM internal02.crm_Product_Metrics_vod__c; +DECLARE table_cursor CURSOR FOR SELECT Id, SystemModstamp, medaca_parent_msj_product_classification__c FROM internal02.crm_Product_Metrics_vod__c; DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE; -- エラー処理 @@ -67,11 +69,12 @@ SET @upsert_statement_base = FROM internal02.crm_Product_Metrics_vod__c AS internaltb WHERE - internaltb.Id = ? + internaltb.Id = ? + AND internaltb.SystemModstamp = ? ON DUPLICATE KEY UPDATE IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, - LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, + LastModifiedById = internaltb.LastModifiedById, MayEdit = internaltb.MayEdit, IsLocked = internaltb.IsLocked, LastViewedDate = internaltb.LastViewedDate, LastReferencedDate = internaltb.LastReferencedDate, Account_vod__c = internaltb.Account_vod__c, Awareness__c = internaltb.Awareness__c, Selling_Stage__c = internaltb.Selling_Stage__c, @@ -109,7 +112,7 @@ OPEN table_cursor; -- ループ TableCursorLoop: LOOP -- スキーマ取得 - FETCH table_cursor INTO temp_table_id, target_column_value; + FETCH table_cursor INTO temp_table_id, temp_system_modstamp, target_column_value; -- 終了条件ループ抜き IF fetch_done THEN @@ -118,12 +121,13 @@ TableCursorLoop: LOOP SET @distribution_schema = internal02.get_distribution_to_schema('crm_Product_Metrics_vod__c', 'medaca_parent_msj_product_classification__c', target_column_value); SET @temp_table_id = temp_table_id; + SET @temp_system_modstamp = temp_system_modstamp; SET @upsert_statement = REPLACE(@upsert_statement_base, "$$distribution_schema$$", @distribution_schema); -- UPSERT実行 PREPARE stmt FROM @upsert_statement; - EXECUTE stmt USING @temp_table_id; + EXECUTE stmt USING @temp_table_id, @temp_system_modstamp; DEALLOCATE PREPARE stmt; END LOOP;