我正在尝试在MySQL中编写一个触发器,我需要设置几个变量的值。我需要放入这些变量的值来自现有表中的一行(不担心多行,只会有一行):
DELIMITER |
CREATE TRIGGER ins_move_to_hist BEFORE INSERT ON EndOfDay
FOR EACH ROW
BEGIN
DECLARE _RowsMatching int;
DECLARE _EodId int(10) unsigned;
DECLARE _Open decimal(6,4);
DECLARE _High decimal(6,4);
DECLARE _Low decimal(6,4);
DECLARE _Close decimal(6,4);
DECLARE _Volume int(10) unsigned;
DECLARE _mtime datetime;
SELECT _RowsMatching = Count(*),
EodId as _EodId,
Open as _Open,
High as _High,
Low as _Low,
Close as _Close,
Volume as _Volume,
mtime as _mtime
from EndOfDay
where DateId = NEW.DateId
and TickerId = NEW.TickerId;
但是,触发器不允许选择结果(我不需要)。所以,当我运行创建脚本时,它给了我这个错误:
不允许返回结果集 来自触发器。
答案 0 :(得分:7)
我相信你只需要将你的as语句改为语句。
更新: 正如比尔在下面纠正我的那样,INTO语句的格式更像是插入语句,即;列列表INTO值列表。
SELECT Count(*), EodId, Open, High, Low, Close, Volume, mtime
INTO _RowsMatching, _EodId, _Open, _High, _Low, _Close, _Volume, _mtime
...
谢谢,比尔。 ;)