【发布时间】:2021-04-27 16:10:51
【问题描述】:
我可以使用 springboot 的中间表在 oracle 表中插入 json 数据
我有一张桌子 abc-
ID first_name last_name cust_ID Active_Ind last_upd_dt
1 abc pqr 101 Y 01-Apr-2021
2 aaa bbb 102 Y 05-Feb-2021
我需要确保—— 如果新的 json 数据具有上述现有值,则不要更新表 abc,保持原样,如果有新记录,则插入。如果新的 json 数据中不存在 oracle 表记录,则将 ACTIVE_IND 更改为 'N'
我尝试使用以下查询插入中间表“test”中不存在的值:
insert into abc
(ID,
first_name,
last_name,
cust_ID,
active_ind,
last_upd_dt)
select
abc_seq.nextval,
first_name,
last_name,
cust_ID,
active_ind,
last_upd_dt
from test t
where not exists(
select null from abc a
where a.fist_name = t.first_name
and a.cust_ID = t.cust_ID);
这在 Oracle 开发人员中运行良好,但是当我在 springboot 中尝试以下查询时,它以某种方式插入重复项,不知道为什么会发生这种情况,我已经为索引使用了准备好的语句。
insert into abc
(ID,
first_name,
last_name,
cust_ID,
active_ind,
last_upd_dt)
select
abc_seq.nextval,
?,
?,
?,
?,
?
from test t
where not exists(
select null from abc a
where a.fist_name = t.first_name
and a.cust_ID = t.cust_ID);```
I have tried merge queries as well, but none of them worked for me.
【问题讨论】:
标签: java sql json oracle spring-boot