Check MySQL version : Buildin Functions « Procedure Function « SQL / MySQL






Check MySQL version

  
mysql>
mysql> delimiter $$
mysql>
mysql>
mysql> CREATE PROCEDURE myProc()
    -> BEGIN
    ->
    ->   IF (CAST(SUBSTR(version(),1,3) AS DECIMAL(2,1)) <5.0) THEN
    ->     SELECT 'MySQL versions earlier than 5.0';
    ->   ELSE
    ->     SELECT 'Thank you are running 5.0 or higher!';
    ->   END IF;
    ->
    -> END$$
Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> delimiter ;
mysql> call myProc();
+--------------------------------------+
| Thank you are running 5.0 or higher! |
+--------------------------------------+
| Thank you are running 5.0 or higher! |
+--------------------------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

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

mysql>

          
  








Related examples in the same category

1.Call buildin math function in your procedure
2.Use Build-in SUM function in a procedure
3.Using String functions in a user-defined function
4.Return the file size by using the LOAD_FILE function
5.An example of a LOOP: test(n) returns once again a string with n asterisks.