zoukankan      html  css  js  c++  java
  • 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/

    复制请注明出处,在世界中挣扎的灰太狼
  • 相关阅读:
    TabControl添加关闭按钮
    C# 遍历窗体上控件方法
    个人JS脚本验证大全[转]
    c# 窗体位置任意调
    Sql存储过程解密算法 破解微软的加密算法
    网页居中
    兼容IE和Firefox的设为首页和收藏的Javascript代码
    定义类成员
    HikariCP
    post请求重定向到get请求问题
  • 原文地址:https://www.cnblogs.com/XingXiaoMeng/p/9594915.html
Copyright © 2011-2022 走看看