IF function in H2 for MySQL compatibility

前端 未结 3 793
梦谈多话
梦谈多话 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:58

    Yes you can create the if function as an alias:

    CREATE ALIAS IF NOT EXISTS `IF` AS $$
        String ifFunction(boolean condition, String exp1, String exp2){
            if(condition) {
                return exp1;
            } else {
                return exp2;
            }
        }
    $$;
    

提交回复
热议问题