zoukankan      html  css  js  c++  java
  • mysql数据库-定义函数-存储过程写法

    -------------

    mysql  定义自定义函数写法

    DELIMITER $$
    
    USE `iwmsdb`$$
    
    DROP FUNCTION IF EXISTS `F_WM_DBNAME`$$
    
    CREATE DEFINER=`mysqladmin`@`%` FUNCTION `F_WM_DBNAME`(v_warehouse_id VARCHAR(50)) RETURNS VARCHAR(50) CHARSET gbk
    BEGIN
       DECLARE V_DB   VARCHAR(50);/*是打发*/
    
       SELECT a.db_name
       INTO V_DB
       FROM iwmsdb.t_wm_db_warehouse a
       WHERE a.warehouse_id = v_warehouse_id;
    
       RETURN V_DB;
    END$$
    
    DELIMITER ;

    ----------------------

    mysql 存储过程写法

    DELIMITER $$
    
    USE `iwmsdb`$$
    
    DROP PROCEDURE IF EXISTS `P_EAP_UI_DELETEINDEXMENU`$$
    
    CREATE DEFINER=`mysqladmin`@`%` PROCEDURE `P_EAP_UI_DELETEINDEXMENU`(IN APP_ID INT)
    BEGIN
        DECLARE MENU_COUNT INT;
        DECLARE MENU_ID VARCHAR(36);
        DECLARE PARENT_MENU_ID VARCHAR(36);
    
        SELECT COUNT(1) INTO MENU_COUNT FROM T_CP_UI_SYSTEMAPP A , T_EAP_SYS_MENU B  WHERE A.FUNCTION_ID=B.MENU_ID;
             IF MENU_COUNT > 0 THEN
             BEGIN
                                         SELECT FUNCTION_ID INTO MENU_ID FROM T_CP_UI_SYSTEMAPP WHERE APP_ID=APP_ID;
                       SELECT PARENT_MENU_ID INTO PARENT_MENU_ID FROM T_EAP_SYS_MENU WHERE MENU_ID = MENU_ID; 
                       SELECT COUNT(1) INTO MENU_COUNT FROM T_EAP_SYS_MENU WHERE PARENT_MENU_ID=PARENT_MENU_ID;
                       IF MENU_COUNT=1 THEN
                       BEGIN
                                DELETE FROM T_EAP_SYS_MENU WHERE MENU_ID IN (MENU_ID,PARENT_MENU_ID);
                                DELETE FROM T_CP_UI_FOLDER WHERE FOLDER_ID=PARENT_MENU_ID;
                                DELETE FROM T_CP_UI_FOLDERREFUSER WHERE FOLDER_ID=PARENT_MENU_ID;
                                DELETE FROM T_EAP_SYS_USER_PRIV WHERE OBJECT_ID IN (MENU_ID,PARENT_MENU_ID);
                       END;
                       ELSE
                       BEGIN
                                DELETE FROM T_EAP_SYS_MENU WHERE MENU_ID = MENU_ID;
                                DELETE FROM T_EAP_SYS_USER_PRIV WHERE OBJECT_ID =MENU_ID;
                       END;
                       END IF;
             END;
             END IF;
    END$$
    
    DELIMITER ;
    自古英雄出炼狱,从来富贵入凡尘。
  • 相关阅读:
    Tomcat的startup.bat启动后显示乱码
    SKF密码设备研究
    《网络攻防》第十一周作业
    《网络攻防》第十周作业
    《网络攻防》第九周作业
    Maven环境搭建以及建立Maven项目
    JavaSE (unbound)的问题解决
    对任性孩子,只要做到“四个不要”就可以了
    layui中对table中的数据进行判断(0、1)转换为提示信息
    Asp.Net Core Mvc上Json序列化首字母大小写的问题
  • 原文地址:https://www.cnblogs.com/yunliu0603/p/10381652.html
Copyright © 2011-2022 走看看