Check version with if statement : IF statement « Procedure Function « SQL / MySQL






Check version with if statement

 
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE myProc()
    -> BEGIN
    ->
    ->     IF (INSTR(version(),'alpha')>0) THEN
    ->               SELECT 'Alpha release of MySQL';
    ->     ELSEIF (INSTR(version(),'beta')>0) THEN
    ->               SELECT 'Beta release of MySQL';
    ->     ELSE
    ->               SELECT 'Production release of MySQL';
    ->     END IF;
    ->
    ->
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql>
mysql> call myProc();
+-----------------------------+
| Production release of MySQL |
+-----------------------------+
| Production release of MySQL |
+-----------------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> drop procedure myProc;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

        








Related examples in the same category

1.IF
2.If statement with ELSEIF and ELSE
3.Using OR in an IF statement
4.IF statement in a LOOP statement