【问题标题】:Set new row value on insert from select statement in Oracle SQLplus在 Oracle SQLplus 中的 select 语句中插入新行值
【发布时间】:2020-10-30 03:43:23
【问题描述】:

是否可以设置触发器以将新行的值设置为 select 语句的结果?我当前的语法如下,但它不起作用:

CREATE TRIGGER "BRAND_NEW_TRIGGER"
    BEFORE INSERT ON my_table
    FOR EACH ROW
BEGIN
    :NEW.column_one := (SELECT details_col FROM other_table WHERE property_id = :NEW.property_id);
END;
/

我已经捏造了上面代码的细节以保护我公司的安全,我知道上面的代码没有太多意义,但我需要以这种方式提取和组织数据是有正当理由的。

【问题讨论】:

    标签: oracle sqlplus


    【解决方案1】:

    你可以做一个select into

    select ot.details_col
      into :new.column_one
      from other_table ot
     where ot.property_id = :new.property_id;
    

    当然,如果这有意义,我会强烈质疑数据模型。这强烈暗示您的数据模型需要一些规范化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多