1
我想創建一個臨時表並從中選擇結果,在一個mysql過程中。MySQL過程臨時表選擇
這裏的一個片的SQL
DELIMITER $$
CREATE PROCEDURE `mydb`.`simulate_results` (currdate DATETIME, enddate DATETIME, idcam INT)
BEGIN
DECLARE MYVAR1,
MYVAR2,
MYVAR3,
IDX INT;
CREATE TEMPORARY TABLE IF NOT EXISTS tmp (
`Id` INT NOT NULL AUTO_INCREMENT,
`Field1` INT NOT NULL,
`Field2` INT NOT NULL,
`Field3` INT NOT NULL, PRIMARY KEY (`Id`)) ENGINE=MEMORY;
INSERT INTO tmp (`Field1`,`Field2`,`Field3`) VALUES (0,0,0);
INSERT INTO tmp (`Field1`,`Field2`,`Field3`) VALUES (1,0,0);
SELECT Field1,Field2,Field3,Id INTO MYVAR1,MYVAR2,MYVAR3,IDXFROM tmp ORDER BY RAND() LIMIT 1;
SELECT MYVAR1; (...)
即來自SELECT INTO statemente填充是IDX(主鍵)的唯一變量。其他人總是空的。
這段代碼有什麼問題嗎?