-------------
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 ;