德比中的条件语句
看起来 derby 不支持条件语句 [IF] 。我们如何
if exists (select 1 from customers where name='somename')
update customers ...
else
insert into customers ...
在德比战中写作? Derby 也没有 mysql 的“替换为”。
注意:我使用 derby 作为 mysql 的单元测试替代品 [即生产将使用 mysql,单元测试将使用 derby]。
It looks like derby doesn't support conditional statements [IF]. How do we write
if exists (select 1 from customers where name='somename')
update customers ...
else
insert into customers ...
in derby? Derby doesn't have 'replace into' of mysql either.
Note: I am using derby as unit-testing replacement for mysql [that is production will use mysql and unit-test will use derby].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://db.apache.org/derby/ 怎么样? docs/10.2/ref/rrefcasenullif.html#rrefcasenullif?
所以也许你可以尝试这样的事情:
我不知道这是否有效,但这似乎是一个开始。祝你好运!
编辑:尝试了其中一些方法后...我不知道这是否真的对您有帮助。看起来你不能在 SELECT 和 INSERT 之间切换;必须是其中之一,然后 CASE 就会进入。你想做的事可能实现,也可能不可能......
What about http://db.apache.org/derby/docs/10.2/ref/rrefcasenullif.html#rrefcasenullif?
So maybe you can try something like:
I have no idea if that would work but it seems like a start. Good luck!
edit: After trying a few of these things out...I don't know if this will really help you. It doesn't seem like you can fire switch between SELECT and INSERT; it has to be one or the other and the CASE goes inside. What you want to do may or may not be possible...
我知道这可能为时已晚,但以防万一有人仍在寻找它:
MERGE
https: //issues.apache.org/jira/browse/DERBY-3155
例如:
MERGE INTO 客户 USING SYSIBM.SYSDUMMY1 ONcustomers.name='somename'
匹配后更新 SET name = 'someothername', ...
当不匹配时插入(id, name, ...) VALUES (DEFAULT, 'someothername', ...)
I know this might be too late but in case anyone is still looking for it:
MERGE
https://issues.apache.org/jira/browse/DERBY-3155
For Example:
MERGE INTO customers USING SYSIBM.SYSDUMMY1 ON customers.name='somename'
WHEN MATCHED THEN UPDATE SET name = 'someothername', ...
WHEN NOT MATCHED THEN INSERT(id, name, ...) VALUES (DEFAULT, 'someothername', ...)