mysql中检测数据库的版本,用到了if语句。
代码如下:
mysql> delimiter $$
mysql> CREATE PROCEDURE myProc() //创建mysql存储过程
-> 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> delimiter ;
mysql> call myProc(); //调用mysql存储过程
+-----------------------------+
| Production release of MySQL |
+-----------------------------+
| Production release of MySQL |
+-----------------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> drop procedure myProc; //删除mysql存储过程
Query OK, 0 rows affected (0.00 sec)