是否可以將準備好的語句的結果設置爲變量?我試圖創建下面的存儲過程,但它失敗:如何從準備好的語句中獲得標量結果?
31行錯誤1064(42000):您的SQL語法錯誤;檢查與你的MySQL服務器版本相對應的手冊,在'stmt USING @m,@c,@a;
DROP PROCEDURE IF EXISTS deleteAction;
DELIMITER $$
CREATE PROCEDURE deleteAction(
IN modul CHAR(64),
IN controller CHAR(64),
IN actn CHAR(64))
MODIFIES SQL DATA
BEGIN
PREPARE stmt FROM 'SELECT id
FROM actions
WHERE `module` = ?
AND `controller` = ?
AND `action` = ?';
SET @m = modul;
SET @c = controller;
SET @a = actn;
SET @i = EXECUTE stmt USING @m, @c, @a;
DEALLOCATE PREPARE stmt;
DELETE FROM acl WHERE action_id = @i;
DELETE FROM actions WHERE id = @i;
END
$$
DELIMITER ;
啊!當然!! – 2010-10-21 22:37:41
我知道這個答案是非常古老的,但任何人都可以告訴我:當我使用這段代碼並使用CALL myProc(600)時,它不返回空查詢結果,而是返回最後一次「有效」調用。爲什麼是這樣的,我該如何改變這一點?當我傳遞一個不在表中的值時,它應該將'result'返回爲空。 – Meelah 2017-10-18 15:11:41