这是我编写的程序 错误代码:1815内部错误:JSON包装器:意外的类型 该查询何时执行其他情况 但是当我将null更改为{}时,效果很好。
**SELECT CASE
WHEN (select count(*) from user_attendance a where a.user_id =userId order by a.user_attn_id desc )!=0 then (select a.bays from user_attendance a where a.user_id =userId order by a.user_attn_id desc limit 1) ELSE null END) );**
与我单独运行
一样,它也可以正常工作**insert into user_attendance(user_id,bays,modified_at,modified_by) values(16,(SELECT CASE
WHEN (select count(*) from user_attendance a where a.user_id =1 order by a.user_attn_id desc )!=0 then (select a.bays from user_attendance a where user_id =1 order by a.user_attn_id desc limit 1)
ELSE null
END),now(),16);**
我不为什么它会表现出这种类型的行为
DROP PROCEDURE `a`.`getTechnicianAttendance`;
DELIMITER $$
CREATE PROCEDURE getTechnicianAttendance()
BEGIN
DECLARE users_count INTEGER DEFAULT 0;
DECLARE finished INTEGER DEFAULT 0;
SELECT count(*) into users_count
FROM user_attendance
WHERE date = current_date();
IF users_count = 0 THEN
Begin
DECLARE userId INTEGER DEFAULT 0;
DECLARE user_id_cursor CURSOR FOR
select users.user_id from users left outer join user_roles on user_roles.user_id = users.user_id where user_roles.role_id = (select role_id from roles where roles.role_name = 'Technician');
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
open user_id_cursor;
user_ids: LOOP
FETCH user_id_cursor INTO userId;
IF finished = 1 THEN
LEAVE user_ids;
END IF;
insert into `autoscope`.`user_attendance` (user_id,
date,
bays
)
values (
userId,
current_date(),
(SELECT CASE
WHEN (select count(*) from user_attendance a where a.user_id =userId order by a.user_attn_id desc )!=0 then (select a.bays from user_attendance a where a.user_id =userId order by a.user_attn_id desc limit 1)
ELSE null
END)
);
END LOOP user_ids;
CLOSE user_id_cursor;
End;
END IF;
END $$