Answer the question
In order to leave comments, you need to log in
What to fix in my procedure?
I'm trying to create a procedure in phpMyAdmin:
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
PROCEDURE `GET_EMPLOYEES_WITH_SALARY_MORE_THAN`(IN `target_salary` INT, OUT `counter` INT)
DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
BEGIN
DECLARE id integer;
DECLARE name, tel varchar(255);
DECLARE acceptanceDate, dismissalDate DATE;
DECLARE salary integer DEFAULT 0;
DECLARE counter integer DEFAULT 0;
Declare done integer DEFAULT 0;
CREATE TEMPORARY TABLE temp LIKE employees;
DECLARE employeeCursor CURSOR FOR SELECT * FROM employees;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;
Open employeeCursor;
WHILE done = 0 DO
FETCH employeeCursor INTO id, name, tel, acceptanceDate, dismissalDate;
SET @p0 = id;
CALL `GET_SALARY`(@p0, @p1);
SELECT @p1 INTO salary;
if (salary >= target_salary) then
INSERT INTO temp SET `idEmployee` = id, `name` = name, `tel` = tel, `acceptanceDate` = acceptanceDate, `dismissalDate` = dismissalDate);
SET counter = counter + 1;
end if;
END WHILE;
Close employeeCursor;
SELECT * FROM temp;
END$$
DELIMITER ;
Answer the question
In order to leave comments, you need to log in
Before the procedure
DELIMITER $$
At the end of the procedure
END $$
DELIMITER ;
CREATE TEMPORARY TABLE temp LIKE employees;
why don't you like it. and even without this line, more errors will come
up : what does the documentation tell us ?
You cannot use CREATE TEMPORY TABLE ... LIKE to create an empty table based on the definition of a table that resides in the mysql tablespace, InnoDB system tablespace (innodb_system), or a general tablespace.
and need to write
CREATE TEMPORARY TABLE `temp` SELECT * FROM `employees` LIMIT 0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question