我有这个程序:
DELIMITER //
CREATE PROCEDURE add_package(nam VARCHAR(255), pack_id INT, lib_id INT, descrip TEXT)
BEGIN
DECLARE ind INT;
DECLARE `_rollback` BOOL DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET `_rollback` = 1;
START TRANSACTION;
INSERT INTO java_master (name, description) VALUES (nam, descrip);
SET ind = (SELECT id FROM java_master WHERE name = nam AND description = descrip);
INSERT INTO java_package (master_id, parent_package_id, library_id) VALUES (ind, pack_id, lib_id);
IF `_rollback` THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END //
DELIMITER ;
我需要在中间设置那个 set 语句,即使描述是空值,也可以id
在java_master
表中返回...关于如何做到这一点的任何建议?