在mysql存储过程中,使用mysql函数version()检测mysql数据库的版本。
代码:
mysql> delimiter $$ 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'; //检测mysql版本 -> ELSE -> SELECT 'Thank you are running 5.0 or higher!'; -> END IF; -> -> END$$ Query OK, 0 rows affected (0.02 sec) mysql> delimiter ; mysql> call myProc(); //调用存储过程 输出当前mysql数据库的版本 +--------------------------------------+ | 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)