【问题标题】:Is it possible to do the same with one statement?是否可以对一个语句做同样的事情?
【发布时间】:2020-08-05 18:18:50
【问题描述】:

在触发器中我有这个逻辑

 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;

是否可以对一个查询执行相同的操作?无论多么先进

【问题讨论】:

  • 不值得。您正在访问表中的不同行。
  • 这是一个必要的要求...我一直在尝试使用 OR 来执行此操作,然后将其推入嵌套表中,但我猜想出了点问题...如果您有任何建议,我将不胜感激。唯一的区别在于 where 子句

标签: sql oracle join plsql oracle11g


【解决方案1】:

考虑条件聚合:

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多