我想使用phpmyadmin在MySQL数据库中创建一个存储过程。
几分钟后,我输入“创建程序”对话框并按GO,我的语法出错了。
我在google上搜索哪一个错了,但仍未找到。请有人给我一些建议如何解决这个问题。
这是我的'MySQL'存储过程查询。
DELIMITER $$
BEGIN
IF cek=1 THEN
SELECT a.NIK AS NIK
, a.EmployeeName AS EmployeeName
, a.Position AS Position
, b.TypeName AS EmployeeType
, TIME(c.EventTime) AS Datang
, (CASE WHEN a.TypeID=3 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM MST_Shift
WHERE ShiftID=(SELECT ShiftID FROM SCH_Shifting WHERE NIK=a.NIK AND DATE(ShiftDate)=DATE(sdate)
AND IsActive=1 AND IsDeleted=0))
THEN 'Late' ELSE 'On Time' END)
WHEN a.TypeID=1 OR a.TypeID=2 THEN
(CASE WHEN TIME(c.EventTime)>'08:15:00' THEN 'Late' ELSE 'On Time' END)
WHEN a.TypeID=6 OR a.TypeID=7 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM MST_Shift
WHERE TypeID=a.TypeID LIMIT 1) THEN 'Late' ELSE 'On Time' END)
WHEN a.TypeID=5 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM MST_Shift
WHERE ShiftID=(CASE WHEN DAYOFWEEK(sdate)=7 THEN 12 ELSE 11 END)) THEN 'Late' ELSE 'OnTime' END)
WHEN a.TypeID=4 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM SCH_Special
WHERE NIK=a.NIK AND DATE(AbsenceDate)=DATE(sdate) AND IsDeleted=0) THEN 'Late' ELSE 'OnTime' END)
ELSE 'Undefined' END) AS Description
FROM MST_Employee a
INNER JOIN MST_EmployeeType b ON b.TypeID=a.TypeID
INNER JOIN VW_AttendanceIN c ON a.NIK=c.NIK
WHERE DATE(c.EventTime)=DATE(sdate)
GROUP BY b.TypeName
, a.Position
, a.EmployeeName;
ELSE
SELECT a.NIK AS NIK
, a.EmployeeName AS EmployeeName
, a.Position AS Posisi
, b.TypeName AS Tipe
, TIME(c.EventTime) AS Datang
, (CASE WHEN a.TypeID=3 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM MST_Shift
WHERE ShiftID=(SELECT ShiftID FROM SCH_Shifting WHERE NIK=a.NIK AND DATE(ShiftDate)=DATE(sdate)
AND IsActive=1 AND IsDeleted=0))
THEN 'Late' ELSE 'On Time' END)
WHEN a.TypeID=1 OR a.TypeID=2 THEN
(CASE WHEN TIME(c.EventTime)>'08:15:00' THEN 'Late' ELSE 'On Time' END)
WHEN a.TypeID=6 OR a.TypeID=7 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM MST_Shift
WHERE TypeID=a.TypeID LIMIT 1) THEN 'Late' ELSE 'On Time' END)
WHEN a.TypeID=5 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM MST_Shift
WHERE ShiftID=(CASE WHEN DAYOFWEEK(sdate)=7 THEN 12 ELSE 11 END)) THEN 'Late' ELSE 'OnTime' END)
WHEN a.TypeID=4 THEN
(CASE WHEN TIME(c.EventTime)>(SELECT TimeIn FROM SCH_Special
WHERE NIK=a.NIK AND DATE(AbsenceDate)=DATE(sdate) AND IsDeleted=0) THEN 'Late' ELSE 'OnTime' END)
ELSE 'Undefined' END) AS Description
FROM MST_Employee a
INNER JOIN MST_EmployeeType b ON b.TypeID=a.TypeID
INNER JOIN VW_AttendanceIN c ON a.NIK=c.NIK
WHERE DATE(c.EventTime)=DATE(sdate)
AND b.TypeID=type
AND (a.NIK LIKE '%'+search+'%' OR a.EmployeeName LIKE '%'+key+'%')
GROUP BY b.TypeName
, a.Position
, a.EmployeeName;
END IF;
END$$
我得到了这样的错误
处理您的请求:
以下查询失败:“CREATE DEFINER =
root
@%
程序USP_SelectAttendance
(INcek
BIT(1),INtype
INT, INsdate
DATETIME,INsearch
VARCHAR(100))NOT DETERMINISTIC包含SQL SQL安全定义器.......MySQL说:#1064 - 你的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'$$ BEGIN IF cek = 1附近使用,然后在第1行选择a.NIK AS NIK,a.EmployeeName AS'
此外,当我在SQL中运行时,'SELECT'查询工作正常。
错误出现在存储过程创建中。
PS:我很抱歉英语不好答案 0 :(得分:1)
变化:
...
AND (a.NIK LIKE '%'+search+'%' OR a.EmployeeName LIKE '%'+key+'%')
...
由:
...
AND (a.NIK LIKE CONCAT('%',search,'%') OR a.EmployeeName LIKE CONCAT('%',`key`,'%'))
...