在 Oracle 中,我可以执行“将值插入或更新到表中”吗?

发布于 2024-09-26 00:33:22 字数 255 浏览 1 评论 0原文

我有一个包含两个数字列的表,以及对它们的唯一约束。我想插入一对新的值,除非该对已经存在。最简单的方法是什么?

如果我这样做

insert into TABLE values (100,200) 

并且该对已经存在,我会收到 ORA-00001 错误,所以我想做类似的事情

insert or update into TABLE values (100,200)

I have a table with two number columns, and a unique constraint over them both. I would like to insert a new pair of values UNLESS the pair already exists. What is the simplest way to do this?

If I do

insert into TABLE values (100,200) 

and the pair already exists I get a ORA-00001 error, so I would like to do something like

insert or update into TABLE values (100,200)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骷髅 2024-10-03 00:33:22

您可以使用 MERGE

You can use MERGE

感受沵的脚步 2024-10-03 00:33:22

你可以尝试这样的事情:

insert into table
select :a, :b from dual
where not exists (select 1 from table where column1 = :a and column2=:b)

You can try something like:

insert into table
select :a, :b from dual
where not exists (select 1 from table where column1 = :a and column2=:b)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文