Combine SQL multiple input statement is not an option

So, concretizing another question ...

I have a merge whose task is to create join table rows from an existing table that can only represent a 1-1 join between objects (PROJECT) and from a table that can represent an N-1 connector (working), a join table (PROJECT- WORKER), every project must have dedicated leaders and every worker must have a project, but now I must have an nn connection ... This merge would do the job:

But unfortunately branch is multiple matched then insert

not a "feature" in sql, how can I solve this problem. Original request ---)

MERGE INTO WORKERPROJECT TARGET
USING (SELECT distinct
               w.worker_id,
               w.worker_type,
               w.project_id worker_project_id, 
               p.project_id project_project_id,
               p.dedicated_project_leader,
               p.dedicated_lead_developer,
               p.dedicated_lead_consultant,
               p.dedicated_supervisor
       from WORKER w 
       join PROJECT p on w.project_id = p.project_id
      ) SOURCE
   ON (SOURCE.worker_type is null)
 WHEN NOT MATCHED THEN INSERT (TARGET.FK_WORKER_ID, TARGET.FK_PROJECT_ID,TARGET.IS_ACTIVE,POSITION) 
  VALUES (SOURCE.WORKER_ID,SOURCE.worker_project_id,'ACTIVE',SOURCE.worker_type);
 WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
  VALUES (SOURCE.dedicated_project_leader,SOURCE.project_project_id,'ACTIVE','PROJECTVEZETŐ');
 WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)  
  INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION) VALUES (SOURCE.dedicated_lead_developer,SOURCE.project_project_id,'ACTIVE','FEJLESZTŐVEZETŐ');
 WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
  INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION) VALUES (SOURCE.dedicated_lead_consultant,SOURCE.project_project_id,'ACTIVE','KONZULENSVEZETŐ');
 WHEN NOT MATCHED THEN INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION)
  INSERT (FK_WORKER_ID, FK_PROJECT_ID,IS_ACTIVE,POSITION) VALUES (SOURCE.dedicated_supervisor,SOURCE.project_project_id,'ACTIVE','SUPERVISOR');

      

+3


source to share


2 answers


Actually, you can. Thanks to insert all

http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9014.htm#i2095116



+3


source


If you need to perform multiple inserts using a merge, add columns from another table to your initial selection. Like that:



'MERGE INTO regional_dummy a 
USING (SELECT c.ID as IDNO FROM   region_country c    WHERE c.parent_id = '2' ) b
ON ('true' = 'false')
--WHEN MATCHED THEN UPDATE <TODO>
WHEN NOT MATCHED THEN
INSERT
(id,REGIONAL_userid,REGIONAL_NAME,REGIONAL_EMAIL,CREATE_DATE,CREATED_BY,REGION_ID,    COUNTRY_ID,PRODUCT_ID,ACTIVE,REPLACE_FLAG0)
VALUES    (REGIONAL_SEQ.nextval,'12345rg','userName','userEmailId',sysdate,  'rgrover0','2',b.IDNO,'m_product_region','Y' ,'N');'

      

0


source







All Articles