假设ID唯一,lsb为保存比较结果的表,VALUE为字段 trubcate lsb SELECT concat('insert into lsb values (',b2.S,条件,')') FROM B1 INNER JOIN B2 ON B1.ID=B2.ID; prepare stml from @aa; execute stml; 打开LSB 判断值or SELECT concat('select ',b2.S,条件,' into @bb') into @aa FROM B1 INNER JOIN B2 ON B1.ID=B2.ID; prepare stml from @aa; execute stml; select @bb;
SELECT concat('select ',b2.S,条件,' into @bb') into @aa FROM B1 INNER JOIN B2 ON B1.ID=B2.ID; prepare stml from @aa; execute stml; select @bb; 执行的结果是什么
触发器如下(在table1上): BEGIN DECLARE aa VARCHAR(20); SET aa = concat(10, new.s); IF aa THEN INSERT INTO table2 VALUES (new.s, 1); ELSE INSERT INTO table2 VALUES (new.s, 0); END IF; END执行后结果如下 table1:table2:
不知道你仔细看过别人的回复没有 你只是赋值,执行没有? SET aa = concat('select ',10, new.s,' into @bb'); prepare stml from @aa; execute stml; select @bb; if @bb=1 then .... else ... end if;
表1
ID 条件
1 >20
表2
ID S
1 10触发器在表2上,现在从表1取出两边ID相等的条件,然后再用S与条件进行比较,结果符合的话再进行下一步,也就是说这里要判断10>20这个条件,但就是不会处理>20这个条件
SELECT *,IF(B1.S>B2.S,你的处理,B1.S) FROM B1 INNER JOIN B2 ON B1.ID=B2.ID
明确定义后计算机才能实现。
trubcate lsb
SELECT concat('insert into lsb values (',b2.S,条件,')') FROM B1 INNER JOIN B2 ON B1.ID=B2.ID;
prepare stml from @aa;
execute stml;
打开LSB 判断值or
SELECT concat('select ',b2.S,条件,' into @bb') into @aa FROM B1 INNER JOIN B2 ON B1.ID=B2.ID;
prepare stml from @aa;
execute stml;
select @bb;
prepare stml from @aa;
execute stml;
select @bb;
执行的结果是什么
BEGIN
DECLARE aa VARCHAR(20);
SET aa = concat(10, new.s);
IF aa THEN
INSERT INTO table2 VALUES (new.s, 1);
ELSE
INSERT INTO table2 VALUES (new.s, 0);
END IF;
END执行后结果如下
table1:table2:
你只是赋值,执行没有?
SET aa = concat('select ',10, new.s,' into @bb');
prepare stml from @aa;
execute stml;
select @bb;
if @bb=1 then
....
else
...
end if;
但是这个还是有个问题,触发器里是不能执行动态sql语句的吧