在 Oracle SQLplus 中从 select 语句插入时设置新行值

Set new row value on insert from select statement in Oracle SQLplus

是否可以设置一个触发器来将新行的值设置为 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;
/

为了保护我公司的安全,我篡改了上面代码的细节,我知道上面的代码没有太大意义,但我有充分的理由需要以这种方式提取和组织数据。

你可以做一个select into

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

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