2014-03-27 98 views
0

我創建的存儲過程來插入數據返回插入記錄的ID,我想插入記錄的ID在同一程序在MySQL存儲過程

DELIMITER $$ 

USE `dbname`$$ 

DROP PROCEDURE IF EXISTS `sp1`$$ 

CREATE DEFINER=`root`@`%` PROCEDURE `sp1`(
    Cname VARCHAR(30), 
    Camount INT(10) 

) 
BEGIN 
    INSERT INTO user( Username, PAmount ) 
VALUES( Cname, Camount) ; 

    END$$ 

DELIMITER ; 

我試圖

SELECT MAX(id) AS pid FROM user; 

但這在明年查詢原因錯誤

錯誤: Commands out of sync; you can't run this command now

回答