Conditional Derby Statements

It seems derby does not support conditional statements [IF]. How to write

if exists (select 1 from customers where name='somename') 
    update customers ...
else 
    insert into customers ...

in the derby? Derby has no "replacement in" mysql.

Note. I use derby as a module replacement for mysql [this will be the use of mysql and unit-test will use the derby].

+5
source share
1 answer

What about 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

So maybe you can try something like:

CASE
 WHEN  select 1 from customers where name='somename' = 1 THEN update...
ELSE  insert...
END

I have no idea if this will work, but it seems like a start. Good luck

:. ... , . , SELECT INSERT; , CASE . , , ...

+2

All Articles