• 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 ;
    自古英雄出炼狱,从来富贵入凡尘。
  • 相关阅读:
    vsprintf解析
    带grub的软盘镜像制作
    SunnyOS准备4
    SunnyOS准备3
    SunnyOS准备1
    汇编第七日
    汇编第六日
    解决k8s集群中mount volume失败的问题
    更新k8s集群的证书
    为k8s集群配置自定义告警
  • 原文地址:https://www.cnblogs.com/yunliu0603/p/10381652.html
Copyright © 2020-2023  润新知