insert into select 中使用序号

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

 

INSERT   INTO  EX_EDM_DAILY_SENDED (ID ,DETAIL_ID,TASK_ID, USER_ID ,PROJECT_ID, DATA_TYPE,EMAIL ,CONTENT3,CONTENT2 ,CONTENT1 ,REAL_STATUS,SHAM_STATUS,OPEN_TIME,OPEN_COUNT,OPEN_IP  ,OPEN_CITY,CLICK_TIME,CLICK_COUNT ,CLICK_IP ,CLICK_CITY ,REGISTE_TIME,SEND_TIME,SEND_IP,SEND_NAME,RESEND_COUNT,CATEGORY ,LOCAL_CODE ,LOCAL_MSG,ESP_CODE  ,ESP_MSG ,DELETE_FLAG,CREATE_TIME,REMARK)   SELECT  EX_EDM_SEQ_DAILY_SENDED.NEXTVAL,ID,TASK_ID, USER_ID ,PROJECT_ID,DATA_TYPE,EMAIL ,CONTENT3,CONTENT2 ,CONTENT1 ,REAL_STATUS,SHAM_STATUS,OPEN_TIME,OPEN_COUNT,OPEN_IP  ,OPEN_CITY,CLICK_TIME,CLICK_COUNT ,CLICK_IP ,CLICK_CITY ,REGISTE_TIME,SEND_TIME,SEND_IP,SEND_NAME,RESEND_COUNT,CATEGORY ,LOCAL_CODE ,LOCAL_MSG,ESP_CODE,ESP_MSG ,DELETE_FLAG,CREATE_TIME,REMARK  FROM  

上以这句在java jdbc里执行是没有问题的.
本文出自 “水滴” 博客,请务必保留此出处http://407882.blog.51cto.com/397882/594736

你可能感兴趣的:(insert into select 中使用序号)