• MySQL 循环分支语法


    ---恢复内容开始---

    Loop循环

    label: LOOP
        statement_list
    
        IF exit_condition THEN
            LEAVE label; 
        END IF; 
    END LOOP label;
    View Code

    Repeat循环

    REPEAT
        statement_list
    UNTIL search_condition END REPEAT;
    View Code

    While循环

    WHILE search_condition DO
        statement_list
    END WHILE;
    View Code

    IF...ELSE分支判断

    IF search_condition THEN
        statement_list
    ELSE
        statement_list
    END IF;
    View Code

    IF...ELSEIF...ELSE分支判断

    IF search_condition THEN
        statement_list
    ELSEIF search_condition THEN
        statement_list
    ELSE
        statement_list
    END IF;
    View Code

    CAST分支判断

    CASE case_value
        WHEN when_value THEN
            statement_list
        ELSE
            statement_list
    END CASE;
    View Code

    创建存储过程(PROCEDURE)

    create PROCEDURE procedure_name([IN|OUT|INOUT] param_name param_type,...)
    BEGIN
        statement_list
    END
    View Code

    删除存储过程(PROCEDURE)

    DROP PROCEDURE procedure_name
    View Code

    查看存储过程(PROCEDURE)

    SELECT
        * 
    FROM
        mysql.proc 
    WHERE
        type = 'PROCEDURE'
    View Code

    创建函数(FUNCTION)

    CREATE FUNCTION function_name(param_name param_type,...)
    RETURNS return_type
    BEGIN
        statement_list
    END
    View Code

    删除函数(FUNCTION)

    DROP FUNCTION IF EXISTS function_name
    View Code

    查看函数(FUNCTION)

    SELECT
        * 
    FROM
        mysql.proc 
    WHERE
        type = 'FUNCTION'
    View Code

    定义变量赋值

    -- 函数(FUNCTION)或存储过程(PROCEDURE)定义变量及赋值
        -- 定义
        DECLARE variable_name variable_type DEFAULT default_value;
        -- 赋值
        SET variable_name = new_value;
        -- 在SELECT查询里进行赋值
        SELECT variable_name := col_name;
    View Code

    关于定义变量赋值的详细说明:https://www.cnblogs.com/EasonJim/p/7966918.html

    关于动态MySQL语句:http://blog.itpub.net/29773961/viewspace-1852824/

    复制请注明出处,在世界中挣扎的灰太狼
  • 相关阅读:
    使用HSQLDB 客户端(jvm自带数据库使用技巧)
    PageHelper分页
    使用exe4j打包Java程序
    有图形界面的聊天程序
    同时收发消息
    服务端和客户端互聊
    使用Scanner
    收发字符串
    收发数字
    建立连接
  • 原文地址:https://www.cnblogs.com/XingXiaoMeng/p/9594915.html
Copyright © 2020-2023  润新知