MySQL Forums
Forum List  »  Stored Procedures

1064 error when create a stored procedure
Posted by: goldli zhang
Date: August 10, 2024 09:36PM

I have defined 2 sp. one, named 'prc_emp_has_24h', success created . and another one, 'prc_filter_block_emp' created failed. the error is

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 'out has24h, out xStartTime, out xEndTime);

sp 'prc_emp_has_24h' code likes
```
CREATE DEFINER=`root`@`localhost` PROCEDURE `prc_ai2soft_emp_has_24h`(IN empNo VARCHAR(24), OUT has24h int(4), OUT startTime DATETIME(6), OUT endTime DATETIME(6))
BEGIN
DECLARE ret INT;

...

IF ret > 0 THEN
set has24h = 1;

...
ELSE
set has24h = 0;
SET startTime = null;
SET endTime = null;
END if;

END
```

and sp 'prc_filter_block_emp' code likes
```

CREATE PROCEDURE prc_filter_block_emp(destDay DATETIME(6))
BEGIN
DECLARE has24h int(4);
DECLARE xStartTime DATETIME(6);
DECLARE xEndTime DATETIME(6);
DECLARE done INT DEFAULT FALSE;

DECLARE cursor_emp CURSOR FOR
SELECT r.pin, r.`name`, r.inorout, r.ttime -- , r.event_point_name
FROM acc_records r
INNER JOIN (
SELECT id, ROW_NUMBER() OVER(PARTITION BY pin ORDER BY ttime DESC) xindex
FROM acc_records
WHERE TO_DAYS(ttime) = TO_DAYS(destDay)
and event_no=0
) src
on r.id = src.id
where src.xindex=1 and r.inorout = 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_emp;
read_emp_loop: LOOP
FETCH cursor_emp INTO empNo, empName, isInOut, ttime;

IF done THEN
LEAVE read_emp_loop;
ELSE
call prc_ai2soft_emp_has_24h(empNo, out has24h, out xStartTime, out xEndTime);

IF has24h THEN -- 如果人员有24门禁权限
IF xStartTime = null AND xEndTime = NULL THEN
CONTINUE;

if xStartTime <= ttime and ttime <= xEndTime THEN
CONTINUE;
END IF;
END IF;
END LOOP read_emp_loop;
CLOSE cursor_emp;
END
```

what is the problem?

Options: ReplyQuote


Subject
Views
Written By
Posted
1064 error when create a stored procedure
451
August 10, 2024 09:36PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.