是否可以用一个语句做同样的事情?
Is it possible to do the same with one statement?
在触发器中我有这个逻辑
SELECT IS_DELETE, IS_EDITABLE INTO is_delete_old, is_delete_old
FROM MAP_CALCULATION MC
INNER JOIN map_calculation_group MG ON MC.ID_CALC = MG.ID_CALC
WHERE MG.ID_CALC = MC.ID_CALC
AND :old.id_group = mg.id_group;
SELECT IS_DELETE, IS_EDITABLE INTO is_delete_new, iis_editable_new
FROM MAP_CALCULATION MC
INNER JOIN map_calculation_group MG ON MC.ID_CALC = MG.ID_CALC
WHERE MG.ID_CALC = MC.ID_CALC
AND mg.id_group = :new.id_group;
是否可以对一个查询执行相同的操作?无论多么先进
考虑条件聚合:
select
max(case when mg.id_group = :new.id_group then is_delete end),
max(case when mg.id_group = :new.id_group then is_editable end),
max(case when mg.id_group = :old.id_group then is_delete end),
max(case when mg.id_group = :old.id_group then is_editable end)
into
is_delete_new,
is_editable_new,
is_delete_old,
is_editable_old
from map_calculation mc
inner join map_calculation_group mg on mc.id_calc = mg.id_calc
where
mg.id_calc = mc.id_calc
and mg.id_group in (:new.id_group, :old.id_group);
在触发器中我有这个逻辑
SELECT IS_DELETE, IS_EDITABLE INTO is_delete_old, is_delete_old
FROM MAP_CALCULATION MC
INNER JOIN map_calculation_group MG ON MC.ID_CALC = MG.ID_CALC
WHERE MG.ID_CALC = MC.ID_CALC
AND :old.id_group = mg.id_group;
SELECT IS_DELETE, IS_EDITABLE INTO is_delete_new, iis_editable_new
FROM MAP_CALCULATION MC
INNER JOIN map_calculation_group MG ON MC.ID_CALC = MG.ID_CALC
WHERE MG.ID_CALC = MC.ID_CALC
AND mg.id_group = :new.id_group;
是否可以对一个查询执行相同的操作?无论多么先进
考虑条件聚合:
select
max(case when mg.id_group = :new.id_group then is_delete end),
max(case when mg.id_group = :new.id_group then is_editable end),
max(case when mg.id_group = :old.id_group then is_delete end),
max(case when mg.id_group = :old.id_group then is_editable end)
into
is_delete_new,
is_editable_new,
is_delete_old,
is_editable_old
from map_calculation mc
inner join map_calculation_group mg on mc.id_calc = mg.id_calc
where
mg.id_calc = mc.id_calc
and mg.id_group in (:new.id_group, :old.id_group);