2012-04-16 121 views
0

有誰知道爲什麼我不斷收到此錯誤在下面?我似乎無法動搖它。MySQL和動態查詢錯誤1064

call test_delete('[email protected]', '''2c016cd6-87e6-11e1-9fac-001cd4565d26''', 0) Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE user u SET u.enable = ? WHERE u.' at line 2

DELIMITER $$  
    CREATE PROCEDURE `test_delete`(
     IN username NVARCHAR(255), 
     IN district_admin_ids LONGTEXT, 
     IN active BIT(1) 
    ) 
    BEGIN 

    SET @username = username; 
    SET @district_admin_ids = district_admin_ids; 
    SET @active = CASE WHEN active > 0 THEN 1 ELSE 0 END; 

    SET @query = CONCAT(' 
         SET SQL_SAFE_UPDATES=0; 
         UPDATE user u 
         SET u.enable = ? 
         WHERE u.id IN (
          SELECT da.id 
          FROM test da 
          WHERE u.id = da.id 
          AND u.username = ? 
          AND da.id IN (?) 
         );'); 

    PREPARE statement FROM @query; 
    EXECUTE statement USING @active, @username, @district_admin_ids; 
    DEALLOCATE PREPARE statement; 
    END 

回答

1

感動SET SQL_SAFE_UPDATES=0;外動態查詢和它的工作。