IF function in H2 for MySQL compatibility

前端 未结 3 778
梦谈多话
梦谈多话 2021-02-13 23:11

I\'m using H2 (with MySQL compatibility mode) to write some automated tests against our software that uses MySQL. Unfortunately, it seems like H2 does not have have the IF

3条回答
  •  臣服心动
    2021-02-13 23:55

    I've just had the same issue, and I resolved it with CASE/WHEN/THEN SQL statement. So you can rewrite your query as follows:

    SELECT CASE WHEN true THEN 'TRUE!!' ELSE 'FALSE!!!' END;
    

    Surely it's more verbose, but it fits both H2 and MySQL.

提交回复
热议问题