レビュー最終修正
This commit is contained in:
parent
9c5ce1ef6c
commit
092225f36d
@ -1,39 +1,52 @@
|
|||||||
CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` ()
|
CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c`()
|
||||||
|
SQL SECURITY INVOKER
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
-- 変数宣言
|
-- 振り分けスキーマ
|
||||||
DECLARE distribution_schema VARCHAR(64);
|
DECLARE distribution_schema VARCHAR(64);
|
||||||
|
-- 振り分けカラム
|
||||||
DECLARE target_column_value VARCHAR(64);
|
DECLARE target_column_value VARCHAR(64);
|
||||||
|
-- 振り分け先テーブルID
|
||||||
DECLARE temp_table_id VARCHAR(18);
|
DECLARE temp_table_id VARCHAR(18);
|
||||||
|
-- カーソルフェッチステータス
|
||||||
DECLARE fetch_done BOOLEAN DEFAULT FALSE;
|
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, medaca_parent_msj_product_classification__c FROM internal02.crm_Product_Metrics_vod__c;
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE;
|
||||||
|
|
||||||
-- エラー処理
|
-- エラー処理
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
BEGIN
|
BEGIN
|
||||||
GET DIAGNOSTICS CONDITION 1
|
GET DIAGNOSTICS CONDITION 1
|
||||||
@error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT;
|
@error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT;
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
SET @error_msg = (
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(@error_msg) > 128 THEN CONCAT(SUBSTRING(@error_msg, 1, 125), '...')
|
||||||
|
ELSE @error_msg
|
||||||
|
END
|
||||||
|
);
|
||||||
SIGNAL SQLSTATE '45000'
|
SIGNAL SQLSTATE '45000'
|
||||||
SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg;
|
SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
START TRANSACTION;
|
||||||
|
|
||||||
-- UPSERT STATEMENT設定
|
-- UPSERT STATEMENT設定
|
||||||
SET @upsert_statement =
|
SET @upsert_statement_base =
|
||||||
'INSERT INTO $$distribution_schema$$.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate,
|
'INSERT INTO $$distribution_schema$$.crm_Product_Metrics_vod__c
|
||||||
LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c,
|
(Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate,
|
||||||
Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c,
|
LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c,
|
||||||
Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__c,
|
Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c,
|
||||||
Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c,
|
Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__c,
|
||||||
MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c,
|
Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c,
|
||||||
EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c,
|
MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c,
|
||||||
EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c,
|
EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c,
|
||||||
MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c,
|
EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c,
|
||||||
MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, start_datetime,
|
MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c,
|
||||||
end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date)
|
MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, start_datetime,
|
||||||
|
end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date)
|
||||||
SELECT
|
SELECT
|
||||||
Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp,
|
Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp,
|
||||||
MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c,
|
MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c,
|
||||||
@ -50,7 +63,7 @@ SET @upsert_statement =
|
|||||||
FROM
|
FROM
|
||||||
internal02.crm_Product_Metrics_vod__c AS internaltb
|
internal02.crm_Product_Metrics_vod__c AS internaltb
|
||||||
WHERE
|
WHERE
|
||||||
Id = $$temp_table_id$$
|
Id = ?
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate,
|
IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate,
|
||||||
CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate,
|
CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate,
|
||||||
@ -87,7 +100,6 @@ SET @upsert_statement =
|
|||||||
file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt,
|
file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt,
|
||||||
upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();';
|
upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();';
|
||||||
|
|
||||||
|
|
||||||
OPEN table_cursor;
|
OPEN table_cursor;
|
||||||
|
|
||||||
-- ループ
|
-- ループ
|
||||||
@ -103,15 +115,15 @@ TableCursorLoop: LOOP
|
|||||||
SET @distribution_schema = get_distribution_to_schema('crm_Product_Metrics_vod__c', 'medaca_parent_msj_product_classification__c', target_column_value);
|
SET @distribution_schema = 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_table_id = temp_table_id;
|
||||||
|
|
||||||
SET @upsert_statement = REPLACE(@upsert_statement, "$$distribution_schema$$", @distribution_schema);
|
SET @upsert_statement = REPLACE(@upsert_statement_base, "$$distribution_schema$$", @distribution_schema);
|
||||||
SET @upsert_statement = REPLACE(@upsert_statement, "$$temp_table_id$$", @temp_table_id);
|
|
||||||
|
|
||||||
-- UPSERT実行
|
-- UPSERT実行
|
||||||
PREPARE stmt FROM @upsert_statement;
|
PREPARE stmt FROM @upsert_statement;
|
||||||
EXECUTE stmt;
|
EXECUTE stmt USING @temp_table_id;
|
||||||
DEALLOCATE PREPARE stmt;
|
DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE table_cursor;
|
CLOSE table_cursor;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
END
|
END
|
||||||
Loading…
x
Reference in New Issue
Block a user