如果您习惯 MySQL,我的问题对您来说可能很简单。我习惯了 PostgreSQL SGBD,我正在尝试将 PL/PgSQL 脚本转换为 MySQL。
这是我所拥有的:
delimiter //
CREATE TRIGGER pgl_new_user
AFTER INSERT ON users FOR EACH ROW
BEGIN
DECLARE m_user_team_id integer;
SELECT id INTO m_user_team_id FROM user_teams WHERE name = "pgl_reporters";
DECLARE m_projects_id integer;
DECLARE cur CURSOR FOR SELECT project_id FROM user_team_project_relationships WHERE user_team_id = m_user_team_id;
OPEN cur;
ins_loop: LOOP
FETCH cur INTO m_projects_id;
IF done THEN
LEAVE ins_loop;
END IF;
INSERT INTO users_projects (user_id, project_id, created_at, updated_at, project_access)
VALUES (NEW.id, m_projects_id, now(), now(), 20);
END LOOP;
CLOSE cur;
END//
但是 MySQL Workbench 给了我一个错误DECLARE m_projects_id
。我真的不明白,因为我在上面两行有相同的指令......
有什么提示吗?
编辑:neubert 解决了这个错误。谢谢。
但是,当我尝试插入用户时:
Error Code: 1329. No data - zero rows fetched, selected, or processed
你有什么主意吗 ?或者更好,你知道我怎样才能得到更好的错误信息吗?