Skip to content

version_major()

xiaoboluo768 edited this page Jun 9, 2020 · 2 revisions
  • 通过version()函数获取并返回MySQL server的主版本号,该函数在MySQL 5.7.9中新增

    • 该函数调用时无需传入任何参数
  • 返回值:一个TINYINT UNSIGNED值

  • 定义语句

DROP FUNCTION IF EXISTS version_major;

DELIMITER $$

CREATE DEFINER='root'@'localhost' FUNCTION version_major ()
    RETURNS TINYINT UNSIGNED
    COMMENT '
            Description
            -----------

            Returns the major version of MySQL Server.

            Returns
            -----------

            TINYINT UNSIGNED

            Example
            -----------

            mysql> SELECT VERSION(), sys.version_major();
            +--------------------------------------+---------------------+
            | VERSION()                            | sys.version_major() |
            +--------------------------------------+---------------------+
            | 5.7.9-enterprise-commercial-advanced | 5                  |
            +--------------------------------------+---------------------+
            1 row in set (0.00 sec)
            '
    SQL SECURITY INVOKER
    NOT DETERMINISTIC
    NO SQL
BEGIN
    RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 1);
END$$

DELIMITER ;

上一篇: sys_get_config()函数 | 下一篇: version_minor()函数

Clone this wiki locally