【问题标题】:can i use select within create command or use triggeer ; help me please sql plus oracle 11g我可以在 create 命令中使用 select 还是使用 trigger ;请帮帮我 sql plus oracle 11g
【发布时间】:2015-08-10 07:03:23
【问题描述】:

我想在插入 account_sh 值时自动计算 account_sh 的新记录和所有以前记录中所有列的新总数

这样

id  account_sh   percentage  total
001    50             1        50

当我插入另一条记录时,它将是****

id     account_sh    percentage    total
001    50             0.25            200
002   150             0.75            200

create table main_sh (
    id_sh number (9),
    account_sh number not null,
    percentage_sh number(*,15) generated always as  (account_sh/total_sh),
    total_sh number generated always as select sum(account_sh) from main_sh);

【问题讨论】:

    标签: oracle oracle11g oracle10g oracle-sqldeveloper sqlplus


    【解决方案1】:

    我相信这样做的方法是在您的表格中添加一个触发器,上面写着:

    IF INSERTING THEN:
        IF :new.total_sh is NULL THEN
            SELECT sum(account_sh) from main_sh into total;
            :new.total_sh := total;
        END IF;
    END IF;
    

    【讨论】:

      猜你喜欢
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      相关资源
      最近更新 更多