insert into select 中使用序号

今天遇到一个问题:

在insert into select后面用序列时报错

insert into R_POL_VIPO(id,SUMVIPONUM,STATSTICSDATE)
select R_POL_VIPO_seq.Nextval,VIPONUM,sysdate
 from R_POL_VIPO
 where YEAR=substr(v_date,0,4) and MONTH=substr(v_date,5);

ORA-02287:此处序号不许使用

将其改成如下形式编译就通过了:

insert into R_POL_VIPO(id,SUMVIPONUM,STATSTICSDATE)
  select R_POL_VIPO_seq.Nextval,b.*
    from (select VIPONUM,sysdate
              from R_POL_VIPO
            where YEAR=substr(v_date,0,4) and MONTH=substr(v_date,5)) b;

你可能感兴趣的:(职场,select,insert,休闲)