From 2ae3b889f07442ffff24f341b6e02101634b964c Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 19 Oct 2023 10:24:40 +0900 Subject: [PATCH 01/12] =?UTF-8?q?Product=5FMetrics=5Fvod=5F=5Fc.sql?= =?UTF-8?q?=E3=81=AE=E3=83=97=E3=83=83=E3=82=B7=E3=83=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql 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 new file mode 100644 index 00000000..81baf252 --- /dev/null +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql @@ -0,0 +1,39 @@ +CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` (target_table VARCHAR(100), target_column VARCHAR(100)) +BEGIN + +-- 変数宣言 +DECLARE distribution_schema VARCHAR(100); +DECLARE target_table VARCHAR(100) DEFAULT 'crm_Product_Metrics_vod__c'; +DECLARE target_column VARCHAR(100); +DECLARE target_column_value VARCHAR(100); +DECLARE TempTableId VARCHAR(18); + +-- カーサー設定 +DECLARE Product_Metrics_vod__c_CURSOR CURSOR FOR +SELECT * FROM internal02.crm_Product_Metrics_vod__c INTO ControlTable; + +-- ループ +ControlTableLoop: WHILE EXISTs (SELECT * FROM ControlTable) +DO + +-- スキーマ取得 +SELECT Id FROM ControlTable ORDER BY Id ASC LIMIT 1 INTO TempTableId; +SELECT medaca_parent_msj_product_classification__c FROM internal02.crm_Product_Metrics_vod__c WHERE Id=TempTableId INTO target_column_value; +SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); + +-- 例外処理、ループ抜け +IF (distribution_schema != src02m OR distribution_schema != src02c) THEN +LEAVE ControlTableLoop; +END IF; + +-- UPSERT文 +INSERT INTO distribution_schema.`crm_Product_Metrics_vod__c` (`Id`, `IsDeleted`, `Name`, `CreatedDate`, `CreatedById`, `LastModifiedDate`, `LastModifiedById`, `SystemModstamp`, `MayEdit`, `IsLocked`, `LastViewedDate`, `LastReferencedDate`, `Account_vod__c`, `Awareness__c`, `Selling_Stage__c`, `Formulary_Status__c`, `Movement__c`, `Products_vod__c`, `Segment__c`, `X12_mo_trx_chg__c`, `Speaker_Skills__c`, `Investigator_Readiness__c`, `Engagements__c`, `Mobile_ID_vod__c`, `External_ID_vod__c`, `MSJ_Patient__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`, `MSJ_EB_2nd_Line_Combination__c`, `MSJ_EB_3rd_Line_Mono__c`, `MSJ_EB_3rd_Line_Combination__c`, `EMDS_Ability__c`, `EMDS_Brand_Loyalty__c`, `EMDS_Decision_Maker__c`, `EMDS_Early_Tech_Adopter__c`, `EMDS_Influence__c`, `EMDS_Main_Driver__c`, `EMDS_Priority__c`, `EMDS_Willingness__c`, `MSJ_KTL_Type__c`, `MSJ_KTL_Tier__c`, `MSJ_Publications__c`, `MSJ_Clinical_Trials__c`, `MSJ_Speaker_for_Medical_Events__c`, `MSJ_Advisor_to_Medical_Affairs__c`, `MSJ_Guidelines_Treatment_Standards__c`, `MSJ_Therapeutic_Area_Expertise__c`, `MSJ_MAP_GAP__c`, `MSJ_Associations__c`, `MSJ_Tier_Score__c`, `medaca_parent_msj_product_classification__c`, `start_datetime`, `end_datetime`, `file_name`, `file_row_cnt`, `delete_flg`, `ins_user`, `ins_date`, `upd_user`, `upd_date`) +SELECT `Id`, `IsDeleted`, `Name`, `CreatedDate`, `CreatedById`, `LastModifiedDate`, `LastModifiedById`, `SystemModstamp`, `MayEdit`, `IsLocked`, `LastViewedDate`, `LastReferencedDate`, `Account_vod__c`, `Awareness__c`, `Selling_Stage__c`, `Formulary_Status__c`, `Movement__c`, `Products_vod__c`, `Segment__c`, `X12_mo_trx_chg__c`, `Speaker_Skills__c`, `Investigator_Readiness__c`, `Engagements__c`, `Mobile_ID_vod__c`, `External_ID_vod__c`, `MSJ_Patient__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`, `MSJ_EB_2nd_Line_Combination__c`, `MSJ_EB_3rd_Line_Mono__c`, `MSJ_EB_3rd_Line_Combination__c`, `EMDS_Ability__c`, `EMDS_Brand_Loyalty__c`, `EMDS_Decision_Maker__c`, `EMDS_Early_Tech_Adopter__c`, `EMDS_Influence__c`, `EMDS_Main_Driver__c`, `EMDS_Priority__c`, `EMDS_Willingness__c`, `MSJ_KTL_Type__c`, `MSJ_KTL_Tier__c`, `MSJ_Publications__c`, `MSJ_Clinical_Trials__c`, `MSJ_Speaker_for_Medical_Events__c`, `MSJ_Advisor_to_Medical_Affairs__c`, `MSJ_Guidelines_Treatment_Standards__c`, `MSJ_Therapeutic_Area_Expertise__c`, `MSJ_MAP_GAP__c`, `MSJ_Associations__c`, `MSJ_Tier_Score__c`, `medaca_parent_msj_product_classification__c`, `start_datetime`, `end_datetime`, `file_name`, `file_row_cnt`, `delete_flg`, `ins_user`, `ins_date`, `upd_user`, `upd_date` +FROM internal02.crm_Product_Metrics_vod__c WHERE Id = TempTableId; + + +-- UPSERT終了後ControlTableから削除 +DELETE FROM ControlTable WHERE Id = TempTableId; +END WHILE; + +END From 1c2a269dc963b548684611b5a8892a1b43897825 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 19 Oct 2023 10:43:36 +0900 Subject: [PATCH 02/12] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E5=AE=A3=E8=A8=80=E6=96=87=E6=B3=95=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal02/crm_distribution_Product_Metrics_vod__c.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 81baf252..fce4c979 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 @@ -9,8 +9,8 @@ DECLARE target_column_value VARCHAR(100); DECLARE TempTableId VARCHAR(18); -- カーサー設定 -DECLARE Product_Metrics_vod__c_CURSOR CURSOR FOR -SELECT * FROM internal02.crm_Product_Metrics_vod__c INTO ControlTable; +DECLARE ControlTable CURSOR FOR +SELECT * FROM internal02.crm_Product_Metrics_vod__c; -- ループ ControlTableLoop: WHILE EXISTs (SELECT * FROM ControlTable) From 685970197722ca632203131fbc019bd35b8ec748 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 19 Oct 2023 16:06:41 +0900 Subject: [PATCH 03/12] =?UTF-8?q?=E9=80=94=E4=B8=AD=E3=83=97=E3=83=83?= =?UTF-8?q?=E3=82=B7=E3=83=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) 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 fce4c979..e2d8d77a 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 @@ -1,39 +1,46 @@ + CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` (target_table VARCHAR(100), target_column VARCHAR(100)) BEGIN +-- エラー処理 +DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + GET DIAGNOSTICS CONDITION 1 + @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; + ROLLBACK; + SIGNAL SQLSTATE '45000' + SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; + END; + -- 変数宣言 DECLARE distribution_schema VARCHAR(100); -DECLARE target_table VARCHAR(100) DEFAULT 'crm_Product_Metrics_vod__c'; -DECLARE target_column VARCHAR(100); DECLARE target_column_value VARCHAR(100); DECLARE TempTableId VARCHAR(18); -- カーサー設定 -DECLARE ControlTable CURSOR FOR -SELECT * FROM internal02.crm_Product_Metrics_vod__c; +SELECT Id, target_column INTO @ControlTable FROM internal02.crm_Product_Metrics_vod__c; -- ループ -ControlTableLoop: WHILE EXISTs (SELECT * FROM ControlTable) -DO +ControlTableLoop: WHILE EXISTS (SELECT * FROM ControlTable) + DO --- スキーマ取得 -SELECT Id FROM ControlTable ORDER BY Id ASC LIMIT 1 INTO TempTableId; -SELECT medaca_parent_msj_product_classification__c FROM internal02.crm_Product_Metrics_vod__c WHERE Id=TempTableId INTO target_column_value; -SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); + -- スキーマ取得 + SELECT Id, target_column FROM ControlTable ORDER BY Id ASC LIMIT 1 INTO TempTableId, target_column_value; + SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); --- 例外処理、ループ抜け -IF (distribution_schema != src02m OR distribution_schema != src02c) THEN -LEAVE ControlTableLoop; -END IF; + -- UPSERT文 + INSERT INTO distribution_schema.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) --- UPSERT文 -INSERT INTO distribution_schema.`crm_Product_Metrics_vod__c` (`Id`, `IsDeleted`, `Name`, `CreatedDate`, `CreatedById`, `LastModifiedDate`, `LastModifiedById`, `SystemModstamp`, `MayEdit`, `IsLocked`, `LastViewedDate`, `LastReferencedDate`, `Account_vod__c`, `Awareness__c`, `Selling_Stage__c`, `Formulary_Status__c`, `Movement__c`, `Products_vod__c`, `Segment__c`, `X12_mo_trx_chg__c`, `Speaker_Skills__c`, `Investigator_Readiness__c`, `Engagements__c`, `Mobile_ID_vod__c`, `External_ID_vod__c`, `MSJ_Patient__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`, `MSJ_EB_2nd_Line_Combination__c`, `MSJ_EB_3rd_Line_Mono__c`, `MSJ_EB_3rd_Line_Combination__c`, `EMDS_Ability__c`, `EMDS_Brand_Loyalty__c`, `EMDS_Decision_Maker__c`, `EMDS_Early_Tech_Adopter__c`, `EMDS_Influence__c`, `EMDS_Main_Driver__c`, `EMDS_Priority__c`, `EMDS_Willingness__c`, `MSJ_KTL_Type__c`, `MSJ_KTL_Tier__c`, `MSJ_Publications__c`, `MSJ_Clinical_Trials__c`, `MSJ_Speaker_for_Medical_Events__c`, `MSJ_Advisor_to_Medical_Affairs__c`, `MSJ_Guidelines_Treatment_Standards__c`, `MSJ_Therapeutic_Area_Expertise__c`, `MSJ_MAP_GAP__c`, `MSJ_Associations__c`, `MSJ_Tier_Score__c`, `medaca_parent_msj_product_classification__c`, `start_datetime`, `end_datetime`, `file_name`, `file_row_cnt`, `delete_flg`, `ins_user`, `ins_date`, `upd_user`, `upd_date`) -SELECT `Id`, `IsDeleted`, `Name`, `CreatedDate`, `CreatedById`, `LastModifiedDate`, `LastModifiedById`, `SystemModstamp`, `MayEdit`, `IsLocked`, `LastViewedDate`, `LastReferencedDate`, `Account_vod__c`, `Awareness__c`, `Selling_Stage__c`, `Formulary_Status__c`, `Movement__c`, `Products_vod__c`, `Segment__c`, `X12_mo_trx_chg__c`, `Speaker_Skills__c`, `Investigator_Readiness__c`, `Engagements__c`, `Mobile_ID_vod__c`, `External_ID_vod__c`, `MSJ_Patient__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`, `MSJ_EB_2nd_Line_Combination__c`, `MSJ_EB_3rd_Line_Mono__c`, `MSJ_EB_3rd_Line_Combination__c`, `EMDS_Ability__c`, `EMDS_Brand_Loyalty__c`, `EMDS_Decision_Maker__c`, `EMDS_Early_Tech_Adopter__c`, `EMDS_Influence__c`, `EMDS_Main_Driver__c`, `EMDS_Priority__c`, `EMDS_Willingness__c`, `MSJ_KTL_Type__c`, `MSJ_KTL_Tier__c`, `MSJ_Publications__c`, `MSJ_Clinical_Trials__c`, `MSJ_Speaker_for_Medical_Events__c`, `MSJ_Advisor_to_Medical_Affairs__c`, `MSJ_Guidelines_Treatment_Standards__c`, `MSJ_Therapeutic_Area_Expertise__c`, `MSJ_MAP_GAP__c`, `MSJ_Associations__c`, `MSJ_Tier_Score__c`, `medaca_parent_msj_product_classification__c`, `start_datetime`, `end_datetime`, `file_name`, `file_row_cnt`, `delete_flg`, `ins_user`, `ins_date`, `upd_user`, `upd_date` -FROM internal02.crm_Product_Metrics_vod__c WHERE Id = TempTableId; + SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date + FROM internal02.crm_Product_Metrics_vod__c AS internaltb + WHERE Id = TempTableId + ON DUPLICATE KEY UPDATE (IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, upd_user, upd_date) + IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, 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, Formulary_Status__c = internaltb.Formulary_Status__c, Movement__c = internaltb.Movement__c, Products_vod__c = internaltb.Products_vod__c, Segment__c = internaltb.Segment__c, X12_mo_trx_chg__c = internaltb.X12_mo_trx_chg__c, Speaker_Skills__c = internaltb.Speaker_Skills__c, Investigator_Readiness__c = internaltb.Investigator_Readiness__c, Engagements__c = internaltb.Engagements__c, Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, External_ID_vod__c = internaltb.External_ID_vod__c, MSJ_Patient__c = internaltb.MSJ_Patient__c, Detail_Group_vod__c = internaltb.Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c = internaltb.MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c = internaltb.MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c = internaltb.MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c = internaltb.MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c = internaltb.MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c = internaltb.MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c = internaltb.EMDS_Ability__c, EMDS_Brand_Loyalty__c = internaltb.EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c = internaltb.EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c = internaltb.EMDS_Early_Tech_Adopter__c, EMDS_Influence__c = internaltb.EMDS_Influence__c, EMDS_Main_Driver__c = internaltb.EMDS_Main_Driver__c, EMDS_Priority__c = internaltb.EMDS_Priority__c, EMDS_Willingness__c = internaltb.EMDS_Willingness__c, MSJ_KTL_Type__c = internaltb.MSJ_KTL_Type__c, MSJ_KTL_Tier__c = internaltb.MSJ_KTL_Tier__c, MSJ_Publications__c = internaltb.MSJ_Publications__c, MSJ_Clinical_Trials__c = internaltb.MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c = internaltb.MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c = internaltb.MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c = internaltb.MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c = internaltb.MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c = internaltb.MSJ_MAP_GAP__c, MSJ_Associations__c = internaltb.MSJ_Associations__c, MSJ_Tier_Score__c = internaltb.MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c = internaltb.medaca_parent_msj_product_classification__c, start_datetime = internaltb.start_datetime, end_datetime = internaltb.end_datetime, file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() + ; --- UPSERT終了後ControlTableから削除 -DELETE FROM ControlTable WHERE Id = TempTableId; + -- UPSERT終了後ControlTableから削除 + DELETE FROM ControlTable WHERE Id = TempTableId; END WHILE; END From ae0a4daa493b8e0ca8e9dfa8c0d4b05991c9acdf Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 19 Oct 2023 16:43:30 +0900 Subject: [PATCH 04/12] =?UTF-8?q?SELECT=E6=96=87=E3=81=AF=E5=BC=95?= =?UTF-8?q?=E6=95=B0=E3=81=8B=E3=82=89=E5=AE=9F=E8=A1=8C=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=83=BBUPSERT=E6=96=87=E6=B3=95=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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 e2d8d77a..32301d14 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 @@ -2,6 +2,11 @@ CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` (target_table VARCHAR(100), target_column VARCHAR(100)) BEGIN +-- 変数宣言 +DECLARE distribution_schema VARCHAR(100); +DECLARE target_column_value VARCHAR(100); +DECLARE TempTableId VARCHAR(18); + -- エラー処理 DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -12,13 +17,8 @@ DECLARE EXIT HANDLER FOR SQLEXCEPTION SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; END; --- 変数宣言 -DECLARE distribution_schema VARCHAR(100); -DECLARE target_column_value VARCHAR(100); -DECLARE TempTableId VARCHAR(18); - -- カーサー設定 -SELECT Id, target_column INTO @ControlTable FROM internal02.crm_Product_Metrics_vod__c; +SELECT Id, target_column INTO @ControlTable FROM internal02.target_table; -- ループ ControlTableLoop: WHILE EXISTS (SELECT * FROM ControlTable) @@ -29,14 +29,13 @@ ControlTableLoop: WHILE EXISTS (SELECT * FROM ControlTable) SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); -- UPSERT文 - INSERT INTO distribution_schema.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) + INSERT INTO distribution_schema.target_table (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date - FROM internal02.crm_Product_Metrics_vod__c AS internaltb + FROM internal02.target_table AS internaltb WHERE Id = TempTableId - ON DUPLICATE KEY UPDATE (IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, upd_user, upd_date) - IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, 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, Formulary_Status__c = internaltb.Formulary_Status__c, Movement__c = internaltb.Movement__c, Products_vod__c = internaltb.Products_vod__c, Segment__c = internaltb.Segment__c, X12_mo_trx_chg__c = internaltb.X12_mo_trx_chg__c, Speaker_Skills__c = internaltb.Speaker_Skills__c, Investigator_Readiness__c = internaltb.Investigator_Readiness__c, Engagements__c = internaltb.Engagements__c, Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, External_ID_vod__c = internaltb.External_ID_vod__c, MSJ_Patient__c = internaltb.MSJ_Patient__c, Detail_Group_vod__c = internaltb.Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c = internaltb.MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c = internaltb.MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c = internaltb.MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c = internaltb.MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c = internaltb.MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c = internaltb.MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c = internaltb.EMDS_Ability__c, EMDS_Brand_Loyalty__c = internaltb.EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c = internaltb.EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c = internaltb.EMDS_Early_Tech_Adopter__c, EMDS_Influence__c = internaltb.EMDS_Influence__c, EMDS_Main_Driver__c = internaltb.EMDS_Main_Driver__c, EMDS_Priority__c = internaltb.EMDS_Priority__c, EMDS_Willingness__c = internaltb.EMDS_Willingness__c, MSJ_KTL_Type__c = internaltb.MSJ_KTL_Type__c, MSJ_KTL_Tier__c = internaltb.MSJ_KTL_Tier__c, MSJ_Publications__c = internaltb.MSJ_Publications__c, MSJ_Clinical_Trials__c = internaltb.MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c = internaltb.MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c = internaltb.MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c = internaltb.MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c = internaltb.MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c = internaltb.MSJ_MAP_GAP__c, MSJ_Associations__c = internaltb.MSJ_Associations__c, MSJ_Tier_Score__c = internaltb.MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c = internaltb.medaca_parent_msj_product_classification__c, start_datetime = internaltb.start_datetime, end_datetime = internaltb.end_datetime, file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() + ON DUPLICATE KEY UPDATE IsDeleted = IsDeleted = VALUES(internaltb.IsDeleted), Name = VALUES(internaltb.Name), CreatedDate = VALUES(internaltb.CreatedDate), CreatedById = VALUES(internaltb.CreatedById), LastModifiedDate = VALUES(internaltb.LastModifiedDate), LastModifiedById = VALUES(internaltb.LastModifiedById), SystemModstamp = VALUES(internaltb.SystemModstamp), MayEdit = VALUES(internaltb.MayEdit), IsLocked = VALUES(internaltb.IsLocked), LastViewedDate = VALUES(internaltb.LastViewedDate), LastReferencedDate = VALUES(internaltb.LastReferencedDate), Account_vod__c = VALUES(internaltb.Account_vod__c), Awareness__c = VALUES(internaltb.Awareness__c), Selling_Stage__c = VALUES(internaltb.Selling_Stage__c), Formulary_Status__c = VALUES(internaltb.Formulary_Status__c), Movement__c = VALUES(internaltb.Movement__c), Products_vod__c = VALUES(internaltb.Products_vod__c), Segment__c = VALUES(internaltb.Segment__c), X12_mo_trx_chg__c = VALUES(internaltb.X12_mo_trx_chg__c), Speaker_Skills__c = VALUES(internaltb.Speaker_Skills__c), Investigator_Readiness__c = VALUES(internaltb.Investigator_Readiness__c), Engagements__c = VALUES(internaltb.Engagements__c), Mobile_ID_vod__c = VALUES(internaltb.Mobile_ID_vod__c), External_ID_vod__c = VALUES(internaltb.External_ID_vod__c), MSJ_Patient__c = VALUES(internaltb.MSJ_Patient__c), Detail_Group_vod__c = VALUES(internaltb.Detail_Group_vod__c), MSJ_EB_1st_Line_Liver_Meta__c = VALUES(internaltb.MSJ_EB_1st_Line_Liver_Meta__c), MSJ_EB_1st_Line_Multi_Meta__c = VALUES(internaltb.MSJ_EB_1st_Line_Multi_Meta__c), MSJ_EB_2nd_Line_Mono__c = VALUES(internaltb.MSJ_EB_2nd_Line_Mono__c), MSJ_EB_2nd_Line_Combination__c = VALUES(internaltb.MSJ_EB_2nd_Line_Combination__c), MSJ_EB_3rd_Line_Mono__c = VALUES(internaltb.MSJ_EB_3rd_Line_Mono__c), MSJ_EB_3rd_Line_Combination__c = VALUES(internaltb.MSJ_EB_3rd_Line_Combination__c), EMDS_Ability__c = VALUES(internaltb.EMDS_Ability__c), EMDS_Brand_Loyalty__c = VALUES(internaltb.EMDS_Brand_Loyalty__c), EMDS_Decision_Maker__c = VALUES(internaltb.EMDS_Decision_Maker__c), EMDS_Early_Tech_Adopter__c = VALUES(internaltb.EMDS_Early_Tech_Adopter__c), EMDS_Influence__c = VALUES(internaltb.EMDS_Influence__c), EMDS_Main_Driver__c = VALUES(internaltb.EMDS_Main_Driver__c), EMDS_Priority__c = VALUES(internaltb.EMDS_Priority__c), EMDS_Willingness__c = VALUES(internaltb.EMDS_Willingness__c), MSJ_KTL_Type__c = VALUES(internaltb.MSJ_KTL_Type__c), MSJ_KTL_Tier__c = VALUES(internaltb.MSJ_KTL_Tier__c), MSJ_Publications__c = VALUES(internaltb.MSJ_Publications__c), MSJ_Clinical_Trials__c = VALUES(internaltb.MSJ_Clinical_Trials__c), MSJ_Speaker_for_Medical_Events__c = VALUES(internaltb.MSJ_Speaker_for_Medical_Events__c), MSJ_Advisor_to_Medical_Affairs__c = VALUES(internaltb.MSJ_Advisor_to_Medical_Affairs__c), MSJ_Guidelines_Treatment_Standards__c = VALUES(internaltb.MSJ_Guidelines_Treatment_Standards__c), MSJ_Therapeutic_Area_Expertise__c = VALUES(internaltb.MSJ_Therapeutic_Area_Expertise__c), MSJ_MAP_GAP__c = VALUES(internaltb.MSJ_MAP_GAP__c), MSJ_Associations__c = VALUES(internaltb.MSJ_Associations__c), MSJ_Tier_Score__c = VALUES(internaltb.MSJ_Tier_Score__c), medaca_parent_msj_product_classification__c = VALUES(internaltb.medaca_parent_msj_product_classification__c), start_datetime = VALUES(internaltb.start_datetime), end_datetime = VALUES(internaltb.end_datetime), file_name = VALUES(internaltb.file_name), file_row_cnt = VALUES(internaltb.file_row_cnt), upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() ; -- UPSERT終了後ControlTableから削除 From f31978134ba9a04e0aa731dc18f5dcacde23bd50 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 19 Oct 2023 16:48:36 +0900 Subject: [PATCH 05/12] =?UTF-8?q?H1=20Insights=20Configuration=E3=81=AE?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E8=A8=AD=E5=AE=9A=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ights__H1_Insights_Configuration__mdt.json | 5 ----- .../crm/object_info/crm_object_list_diff.json | 21 ------------------- 2 files changed, 26 deletions(-) delete mode 100644 s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json diff --git a/s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json b/s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json deleted file mode 100644 index d7b52ba2..00000000 --- a/s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "last_fetch_datetime_from": "1900-01-01T00:00:00.000Z", - "last_fetch_datetime_to": "" -} - \ No newline at end of file diff --git a/s3/config/crm/object_info/crm_object_list_diff.json b/s3/config/crm/object_info/crm_object_list_diff.json index 48d6fac0..48b6460a 100644 --- a/s3/config/crm/object_info/crm_object_list_diff.json +++ b/s3/config/crm/object_info/crm_object_list_diff.json @@ -3267,27 +3267,6 @@ "is_skip": false, "is_update_last_fetch_datetime": true }, - { - "object_name": "H1Insights__H1_Insights_Configuration__mdt", - "columns": [ - "Id", - "DeveloperName", - "MasterLabel", - "Language", - "NamespacePrefix", - "Label", - "QualifiedApiName", - "SystemModstamp", - "H1Insights__API_Endpoint__c", - "H1Insights__API_Key__c", - "H1Insights__H1_Customer_ID__c", - "H1Insights__Support_Email_Address__c", - "H1Insights__Testing_H1_Person_ID__c", - "H1Insights__Testing_NPI_Number__c" - ], - "is_skip": false, - "is_update_last_fetch_datetime": true - }, { "object_name": "Publication__c", "columns": [ From 5136041e7bfde91dde02cdd8f17158c351d4ff9b Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Fri, 20 Oct 2023 09:17:31 +0900 Subject: [PATCH 06/12] =?UTF-8?q?Revert=20"H1=20Insights=20Configuration?= =?UTF-8?q?=E3=81=AE=E5=8F=96=E5=BE=97=E8=A8=AD=E5=AE=9A=E5=89=8A=E9=99=A4?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f31978134ba9a04e0aa731dc18f5dcacde23bd50. --- ...ights__H1_Insights_Configuration__mdt.json | 5 +++++ .../crm/object_info/crm_object_list_diff.json | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json diff --git a/s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json b/s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json new file mode 100644 index 00000000..d7b52ba2 --- /dev/null +++ b/s3/config/crm/last_fetch_datetime/H1Insights__H1_Insights_Configuration__mdt.json @@ -0,0 +1,5 @@ +{ + "last_fetch_datetime_from": "1900-01-01T00:00:00.000Z", + "last_fetch_datetime_to": "" +} + \ No newline at end of file diff --git a/s3/config/crm/object_info/crm_object_list_diff.json b/s3/config/crm/object_info/crm_object_list_diff.json index 48b6460a..48d6fac0 100644 --- a/s3/config/crm/object_info/crm_object_list_diff.json +++ b/s3/config/crm/object_info/crm_object_list_diff.json @@ -3267,6 +3267,27 @@ "is_skip": false, "is_update_last_fetch_datetime": true }, + { + "object_name": "H1Insights__H1_Insights_Configuration__mdt", + "columns": [ + "Id", + "DeveloperName", + "MasterLabel", + "Language", + "NamespacePrefix", + "Label", + "QualifiedApiName", + "SystemModstamp", + "H1Insights__API_Endpoint__c", + "H1Insights__API_Key__c", + "H1Insights__H1_Customer_ID__c", + "H1Insights__Support_Email_Address__c", + "H1Insights__Testing_H1_Person_ID__c", + "H1Insights__Testing_NPI_Number__c" + ], + "is_skip": false, + "is_update_last_fetch_datetime": true + }, { "object_name": "Publication__c", "columns": [ From e21f0d48fa8c91ba678ec5f0b6e96ee1833fb642 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 08:56:01 +0900 Subject: [PATCH 07/12] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=82=BD=E3=83=AB?= =?UTF-8?q?=E3=83=BB=E3=82=B9=E3=83=86=E3=83=BC=E3=83=88=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88SQL=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 102 ++++++++++++++---- 1 file changed, 82 insertions(+), 20 deletions(-) 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 32301d14..ab6956e9 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 @@ -1,11 +1,12 @@ -CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` (target_table VARCHAR(100), target_column VARCHAR(100)) +CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` () BEGIN -- 変数宣言 -DECLARE distribution_schema VARCHAR(100); -DECLARE target_column_value VARCHAR(100); -DECLARE TempTableId VARCHAR(18); +DECLARE distribution_schema VARCHAR(64); +DECLARE target_column_value VARCHAR(64); +DECLARE temp_table_id VARCHAR(18); +DECLARE fetch_done BOOLEAN DEFAULT FALSE; -- エラー処理 DECLARE EXIT HANDLER FOR SQLEXCEPTION @@ -17,29 +18,90 @@ DECLARE EXIT HANDLER FOR SQLEXCEPTION SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; END; +-- UPSERT STATEMENT設定 +SET @upsert_statement = + 'INSERT INTO ?.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) + + SELECT + Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, + MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, + Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, + Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, + MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, + EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, + EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, + MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, + MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, + MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, + start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date + FROM + internal02.crm_Product_Metrics_vod__c AS internaltb + WHERE + Id = ? + + 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, + 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, + Formulary_Status__c = internaltb.Formulary_Status__c, Movement__c = internaltb.Movement__c, + Products_vod__c = internaltb.Products_vod__c, Segment__c = internaltb.Segment__c, + X12_mo_trx_chg__c = internaltb.X12_mo_trx_chg__c, Speaker_Skills__c = internaltb.Speaker_Skills__c, + Investigator_Readiness__c = internaltb.Investigator_Readiness__c, Engagements__c = internaltb.Engagements__c, + Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, External_ID_vod__c = internaltb.External_ID_vod__c, + MSJ_Patient__c = internaltb.MSJ_Patient__c, Detail_Group_vod__c = internaltb.Detail_Group_vod__c, + MSJ_EB_1st_Line_Liver_Meta__c = internaltb.MSJ_EB_1st_Line_Liver_Meta__c, + MSJ_EB_1st_Line_Multi_Meta__c = internaltb.MSJ_EB_1st_Line_Multi_Meta__c, + MSJ_EB_2nd_Line_Mono__c = internaltb.MSJ_EB_2nd_Line_Mono__c, + MSJ_EB_2nd_Line_Combination__c = internaltb.MSJ_EB_2nd_Line_Combination__c, + MSJ_EB_3rd_Line_Mono__c = internaltb.MSJ_EB_3rd_Line_Mono__c, + MSJ_EB_3rd_Line_Combination__c = internaltb.MSJ_EB_3rd_Line_Combination__c, + EMDS_Ability__c = internaltb.EMDS_Ability__c, EMDS_Brand_Loyalty__c = internaltb.EMDS_Brand_Loyalty__c, + EMDS_Decision_Maker__c = internaltb.EMDS_Decision_Maker__c, + EMDS_Early_Tech_Adopter__c = internaltb.EMDS_Early_Tech_Adopter__c, + EMDS_Influence__c = internaltb.EMDS_Influence__c, EMDS_Main_Driver__c = internaltb.EMDS_Main_Driver__c, + EMDS_Priority__c = internaltb.EMDS_Priority__c, EMDS_Willingness__c = internaltb.EMDS_Willingness__c, + MSJ_KTL_Type__c = internaltb.MSJ_KTL_Type__c, MSJ_KTL_Tier__c = internaltb.MSJ_KTL_Tier__c, + MSJ_Publications__c = internaltb.MSJ_Publications__c, MSJ_Clinical_Trials__c = internaltb.MSJ_Clinical_Trials__c, + MSJ_Speaker_for_Medical_Events__c = internaltb.MSJ_Speaker_for_Medical_Events__c, + MSJ_Advisor_to_Medical_Affairs__c = internaltb.MSJ_Advisor_to_Medical_Affairs__c, + MSJ_Guidelines_Treatment_Standards__c = internaltb.MSJ_Guidelines_Treatment_Standards__c, + MSJ_Therapeutic_Area_Expertise__c = internaltb.MSJ_Therapeutic_Area_Expertise__c, + MSJ_MAP_GAP__c = internaltb.MSJ_MAP_GAP__c, MSJ_Associations__c = internaltb.MSJ_Associations__c, + MSJ_Tier_Score__c = internaltb.MSJ_Tier_Score__c, + medaca_parent_msj_product_classification__c = internaltb.medaca_parent_msj_product_classification__c, + start_datetime = internaltb.start_datetime, end_datetime = internaltb.end_datetime, + file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt, + upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() + ;'; + -- カーサー設定 -SELECT Id, target_column INTO @ControlTable FROM internal02.target_table; +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; +OPEN table_cursor; -- ループ -ControlTableLoop: WHILE EXISTS (SELECT * FROM ControlTable) - DO - +TableCursorLoop: LOOP -- スキーマ取得 - SELECT Id, target_column FROM ControlTable ORDER BY Id ASC LIMIT 1 INTO TempTableId, target_column_value; - SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); + FETCH table_cursor INTO temp_table_id, target_column_value; - -- UPSERT文 - INSERT INTO distribution_schema.target_table (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) + -- 終了条件ループ抜き + IF fetch_done THEN + LEAVE TableCursorLoop; + END IF; - SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date - FROM internal02.target_table AS internaltb - WHERE Id = TempTableId + 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; - ON DUPLICATE KEY UPDATE IsDeleted = IsDeleted = VALUES(internaltb.IsDeleted), Name = VALUES(internaltb.Name), CreatedDate = VALUES(internaltb.CreatedDate), CreatedById = VALUES(internaltb.CreatedById), LastModifiedDate = VALUES(internaltb.LastModifiedDate), LastModifiedById = VALUES(internaltb.LastModifiedById), SystemModstamp = VALUES(internaltb.SystemModstamp), MayEdit = VALUES(internaltb.MayEdit), IsLocked = VALUES(internaltb.IsLocked), LastViewedDate = VALUES(internaltb.LastViewedDate), LastReferencedDate = VALUES(internaltb.LastReferencedDate), Account_vod__c = VALUES(internaltb.Account_vod__c), Awareness__c = VALUES(internaltb.Awareness__c), Selling_Stage__c = VALUES(internaltb.Selling_Stage__c), Formulary_Status__c = VALUES(internaltb.Formulary_Status__c), Movement__c = VALUES(internaltb.Movement__c), Products_vod__c = VALUES(internaltb.Products_vod__c), Segment__c = VALUES(internaltb.Segment__c), X12_mo_trx_chg__c = VALUES(internaltb.X12_mo_trx_chg__c), Speaker_Skills__c = VALUES(internaltb.Speaker_Skills__c), Investigator_Readiness__c = VALUES(internaltb.Investigator_Readiness__c), Engagements__c = VALUES(internaltb.Engagements__c), Mobile_ID_vod__c = VALUES(internaltb.Mobile_ID_vod__c), External_ID_vod__c = VALUES(internaltb.External_ID_vod__c), MSJ_Patient__c = VALUES(internaltb.MSJ_Patient__c), Detail_Group_vod__c = VALUES(internaltb.Detail_Group_vod__c), MSJ_EB_1st_Line_Liver_Meta__c = VALUES(internaltb.MSJ_EB_1st_Line_Liver_Meta__c), MSJ_EB_1st_Line_Multi_Meta__c = VALUES(internaltb.MSJ_EB_1st_Line_Multi_Meta__c), MSJ_EB_2nd_Line_Mono__c = VALUES(internaltb.MSJ_EB_2nd_Line_Mono__c), MSJ_EB_2nd_Line_Combination__c = VALUES(internaltb.MSJ_EB_2nd_Line_Combination__c), MSJ_EB_3rd_Line_Mono__c = VALUES(internaltb.MSJ_EB_3rd_Line_Mono__c), MSJ_EB_3rd_Line_Combination__c = VALUES(internaltb.MSJ_EB_3rd_Line_Combination__c), EMDS_Ability__c = VALUES(internaltb.EMDS_Ability__c), EMDS_Brand_Loyalty__c = VALUES(internaltb.EMDS_Brand_Loyalty__c), EMDS_Decision_Maker__c = VALUES(internaltb.EMDS_Decision_Maker__c), EMDS_Early_Tech_Adopter__c = VALUES(internaltb.EMDS_Early_Tech_Adopter__c), EMDS_Influence__c = VALUES(internaltb.EMDS_Influence__c), EMDS_Main_Driver__c = VALUES(internaltb.EMDS_Main_Driver__c), EMDS_Priority__c = VALUES(internaltb.EMDS_Priority__c), EMDS_Willingness__c = VALUES(internaltb.EMDS_Willingness__c), MSJ_KTL_Type__c = VALUES(internaltb.MSJ_KTL_Type__c), MSJ_KTL_Tier__c = VALUES(internaltb.MSJ_KTL_Tier__c), MSJ_Publications__c = VALUES(internaltb.MSJ_Publications__c), MSJ_Clinical_Trials__c = VALUES(internaltb.MSJ_Clinical_Trials__c), MSJ_Speaker_for_Medical_Events__c = VALUES(internaltb.MSJ_Speaker_for_Medical_Events__c), MSJ_Advisor_to_Medical_Affairs__c = VALUES(internaltb.MSJ_Advisor_to_Medical_Affairs__c), MSJ_Guidelines_Treatment_Standards__c = VALUES(internaltb.MSJ_Guidelines_Treatment_Standards__c), MSJ_Therapeutic_Area_Expertise__c = VALUES(internaltb.MSJ_Therapeutic_Area_Expertise__c), MSJ_MAP_GAP__c = VALUES(internaltb.MSJ_MAP_GAP__c), MSJ_Associations__c = VALUES(internaltb.MSJ_Associations__c), MSJ_Tier_Score__c = VALUES(internaltb.MSJ_Tier_Score__c), medaca_parent_msj_product_classification__c = VALUES(internaltb.medaca_parent_msj_product_classification__c), start_datetime = VALUES(internaltb.start_datetime), end_datetime = VALUES(internaltb.end_datetime), file_name = VALUES(internaltb.file_name), file_row_cnt = VALUES(internaltb.file_row_cnt), upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() - ; + -- UPSERT実行 + PREPARE stmt FROM @upsert_statement USING @distribution_schema, @temp_table_id; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; - -- UPSERT終了後ControlTableから削除 - DELETE FROM ControlTable WHERE Id = TempTableId; -END WHILE; +END LOOP; +CLOSE table_cursor; END From eef88cd7cd37a355b5a5c59df4b0d4224ef90b7a Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 09:05:20 +0900 Subject: [PATCH 08/12] =?UTF-8?q?USING=E3=82=B9=E3=83=86=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal02/crm_distribution_Product_Metrics_vod__c.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ab6956e9..930cdcea 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 @@ -97,8 +97,8 @@ TableCursorLoop: LOOP SET @temp_table_id = temp_table_id; -- UPSERT実行 - PREPARE stmt FROM @upsert_statement USING @distribution_schema, @temp_table_id; - EXECUTE stmt; + PREPARE stmt FROM @upsert_statement; + EXECUTE stmt USING @distribution_schema, @temp_table_id; DEALLOCATE PREPARE stmt; END LOOP; From 235130121edaa6e143d45aadbbd7e0f06825fc0b Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 09:20:28 +0900 Subject: [PATCH 09/12] =?UTF-8?q?DECLARE=E6=96=87=E5=85=88=E9=A0=AD?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crm_distribution_Product_Metrics_vod__c.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 930cdcea..99b27018 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 @@ -1,4 +1,3 @@ - CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` () BEGIN @@ -8,6 +7,10 @@ DECLARE target_column_value VARCHAR(64); DECLARE temp_table_id VARCHAR(18); 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 CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE; + -- エラー処理 DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -75,12 +78,9 @@ SET @upsert_statement = medaca_parent_msj_product_classification__c = internaltb.medaca_parent_msj_product_classification__c, start_datetime = internaltb.start_datetime, end_datetime = internaltb.end_datetime, 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();'; + --- カーサー設定 -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; OPEN table_cursor; -- ループ From 9c5ce1ef6c8d1c08270ad52e92bf022cb42b9656 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 13:31:36 +0900 Subject: [PATCH 10/12] =?UTF-8?q?=E9=80=94=E4=B8=AD=E3=83=97=E3=83=83?= =?UTF-8?q?=E3=82=B7=E3=83=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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 99b27018..34b43a22 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 @@ -23,8 +23,17 @@ DECLARE EXIT HANDLER FOR SQLEXCEPTION -- UPSERT STATEMENT設定 SET @upsert_statement = - 'INSERT INTO ?.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) - + 'INSERT INTO $$distribution_schema$$.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, + LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, + Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, + Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, + MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, + EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, + EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, + MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, + 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 Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, @@ -36,13 +45,12 @@ SET @upsert_statement = EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, - MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, - start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date + 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 FROM internal02.crm_Product_Metrics_vod__c AS internaltb WHERE - Id = ? - + Id = $$temp_table_id$$ ON DUPLICATE KEY UPDATE IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, @@ -75,7 +83,6 @@ SET @upsert_statement = MSJ_Therapeutic_Area_Expertise__c = internaltb.MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c = internaltb.MSJ_MAP_GAP__c, MSJ_Associations__c = internaltb.MSJ_Associations__c, MSJ_Tier_Score__c = internaltb.MSJ_Tier_Score__c, - medaca_parent_msj_product_classification__c = internaltb.medaca_parent_msj_product_classification__c, start_datetime = internaltb.start_datetime, end_datetime = internaltb.end_datetime, file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();'; @@ -93,12 +100,15 @@ TableCursorLoop: LOOP LEAVE TableCursorLoop; END IF; - 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 @upsert_statement = REPLACE(@upsert_statement, "$$distribution_schema$$", @distribution_schema); + SET @upsert_statement = REPLACE(@upsert_statement, "$$temp_table_id$$", @temp_table_id); -- UPSERT実行 PREPARE stmt FROM @upsert_statement; - EXECUTE stmt USING @distribution_schema, @temp_table_id; + EXECUTE stmt; DEALLOCATE PREPARE stmt; END LOOP; From 092225f36d06c028b5b72ab867a1ba5531ed6ae5 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 14:41:05 +0900 Subject: [PATCH 11/12] =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E6=9C=80=E7=B5=82=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) 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 34b43a22..bf517a21 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 @@ -1,39 +1,52 @@ -CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` () +CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c`() +SQL SECURITY INVOKER BEGIN --- 変数宣言 +-- 振り分けスキーマ DECLARE distribution_schema VARCHAR(64); +-- 振り分けカラム DECLARE target_column_value VARCHAR(64); +-- 振り分け先テーブルID DECLARE temp_table_id VARCHAR(18); +-- カーソルフェッチステータス 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 CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE; -- エラー処理 -DECLARE EXIT HANDLER FOR SQLEXCEPTION + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN GET DIAGNOSTICS CONDITION 1 @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; ROLLBACK; + SET @error_msg = ( + CASE + WHEN LENGTH(@error_msg) > 128 THEN CONCAT(SUBSTRING(@error_msg, 1, 125), '...') + ELSE @error_msg + END + ); SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; END; +START TRANSACTION; + -- UPSERT STATEMENT設定 -SET @upsert_statement = - 'INSERT INTO $$distribution_schema$$.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, - LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, - Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, - Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, - MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, - EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, - EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, - MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, - 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) +SET @upsert_statement_base = + 'INSERT INTO $$distribution_schema$$.crm_Product_Metrics_vod__c + (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, + LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, + Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, + Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__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, + MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, + EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, + EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, + MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, + 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 Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, @@ -50,7 +63,7 @@ SET @upsert_statement = FROM internal02.crm_Product_Metrics_vod__c AS internaltb WHERE - Id = $$temp_table_id$$ + Id = ? ON DUPLICATE KEY UPDATE IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, 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, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();'; - 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 @temp_table_id = temp_table_id; - SET @upsert_statement = REPLACE(@upsert_statement, "$$distribution_schema$$", @distribution_schema); - SET @upsert_statement = REPLACE(@upsert_statement, "$$temp_table_id$$", @temp_table_id); + SET @upsert_statement = REPLACE(@upsert_statement_base, "$$distribution_schema$$", @distribution_schema); -- UPSERT実行 PREPARE stmt FROM @upsert_statement; - EXECUTE stmt; + EXECUTE stmt USING @temp_table_id; DEALLOCATE PREPARE stmt; END LOOP; CLOSE table_cursor; +COMMIT; -END +END \ No newline at end of file From 1c3121cab4c198d265c14cc5f7affd07bc5fbb94 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 14:43:04 +0900 Subject: [PATCH 12/12] =?UTF-8?q?=E3=82=B9=E3=82=AD=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E5=90=8D=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 bf517a21..2df08345 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 @@ -1,4 +1,4 @@ -CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c`() +CREATE PROCEDURE `internal02`.`crm_distribution_Product_Metrics_vod__c`() SQL SECURITY INVOKER BEGIN @@ -16,20 +16,20 @@ DECLARE table_cursor CURSOR FOR SELECT Id, medaca_parent_msj_product_classificat DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE; -- エラー処理 - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; - ROLLBACK; - SET @error_msg = ( - CASE - WHEN LENGTH(@error_msg) > 128 THEN CONCAT(SUBSTRING(@error_msg, 1, 125), '...') - ELSE @error_msg - END - ); - SIGNAL SQLSTATE '45000' - SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; - END; +DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + GET DIAGNOSTICS CONDITION 1 + @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; + ROLLBACK; + SET @error_msg = ( + CASE + WHEN LENGTH(@error_msg) > 128 THEN CONCAT(SUBSTRING(@error_msg, 1, 125), '...') + ELSE @error_msg + END + ); + SIGNAL SQLSTATE '45000' + SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; + END; START TRANSACTION;