简体   繁体   中英

Insert all and validate duplicates in Oracle from DataFactory

I must execute multiple insert from azure data factory to Oracle and I am using the following statement

INSERT ALL INTO TABLENAME (CTCPIA,CTAN01,CTAN02,CTCRCD,CTCRR,CTAAN05,CTAAN04,CTCRCA,CTCRRB,CTDL011,CTDSG,CTCSIC,CTCPIL,CTEDDJ,CTUSER,CTPID,CTMKEY,CTUPMJ,CTTDAY) SELECT 'XXXX','31028775300.00','31028775300.00','COP','1','0.00','0.00','COP','0.00','Published','Executing','XXXX','XXXX','123059','LAKE-CHEC','XXX','XXX','122097','165729' FROM dual WHERE NOT EXISTS (SELECT 1 FROM TABLENAME WHERE CTCPIA='XXXX') SELECT * FROM dual;

I am adding the lines WHERE NOT EXISTS (SELECT 1 FROM TABLENAME WHERE CTCPIA='XXXX') to validate that no duplicates are inserted, however from datafactory it is throwing me the following error

在此处输入图像描述

How could I validate duplicates within the INSERT ALL statement? since I have to execute a lot of INSERT statements.

Thanks a lot.

I would suggest to refer documentation for INSERT ALL (Section: "The multitable insert statement looks like this")

I performed an insert to explain the scenario, see if that matches your use-case.

Current state of a table -

select * from test;

   ID NAME
----- ----------
    1 adsa
    2 fa
    2 xxx

Inserting 'ALL' to table TEST to avoid duplicates based on condition (value NOT EXISTS)- No rows are inserted.

insert all
into test (id, name)
values (id+1, name||'a')
into test (id, name)
values (id+2, name||'b')
into test (id, name)
values (id+3, name||'c')
select 1 as id,'any name' as name from dual
where NOT EXISTS
(select 1 from test where name='xxx');

0 rows created.

Inserting 'ALL' to table TEST based on condition (value EXISTS)-

insert all
into test (id, name)
values (id+1, name||'a')
into test (id, name)
values (id+2, name||'b')
into test (id, name)
values (id+3, name||'c')
select 1 as id,'any name' as name from dual
where EXISTS
(select 1 from test where name='xxx');

3 rows created.

select * from test;

   ID NAME
----- ----------
    1 adsa
    2 fa
    2 xxx
    2 any namea
    3 any nameb
    4 any namec

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM