mysql存储过程中if...else常见用法

CREATE DEFINER=`root`@`localhost` PROCEDURE `system_depatment_insert`(IN dept_name VARCHAR(50),IN dept_parent_id VARCHAR(32),IN dept_hava_child VARCHAR(1),IN dept_description VARCHAR(100))
BEGIN
	IF(dept_parent_id IS NULL || dept_parent_id = '') THEN
		INSERT INTO oa.department VALUES(REPLACE(UUID(),'-',''),dept_name,'00','顶层部门',dept_hava_child,dept_description,NOW());
	ELSE
		SET @dept_parent_name = (SELECT parent_name FROM oa.department WHERE id = dept_parent_id);
		INSERT INTO oa.department VALUES(REPLACE(UUID(),'-',''),dept_name,dept_parent_id,dept_parent_name,dept_hava_child,dept_description,NOW());
	END IF;
    END$$

记:mysql中判断使用=,编程习惯了老是写==,很容易忽略

你可能感兴趣的:(mysql存储过程中if...else常见用法)