条件语句 [英] conditional statements in derby
问题描述
它似乎 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 ...
Derby没有'replace into'的mysql。
in derby? Derby doesn't have 'replace into' of mysql either.
注意:我使用derby作为单元测试替换mysql [生产将使用mysql和单位-test将使用derby。
Note: I am using derby as unit-testing replacement for mysql [that is production will use mysql and unit-test will use derby].
推荐答案
http://db.apache.org/derby/docs/10.2/ref/rrefcasenullif.html#rrefcasenullif ?
CASE
WHEN 1 = 2 THEN 3
WHEN 4 = 5 THEN 6
ELSE 7
END
也许你可以试试:
CASE
WHEN select 1 from customers where name='somename' = 1 THEN update...
ELSE insert...
END
我不知道这是否可行,但似乎是一个开始。祝你好运!
I have no idea if that would work but it seems like a start. Good luck!
编辑:尝试了一些这些东西后...我不知道这是否真的会帮助你。它似乎不是你可以在SELECT和INSERT之间切换;它必须是一个或另一个和CASE进去。你想做什么可能或可能不可能...
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...
这篇关于条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!