Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

oracle - ORA-02287: sequence number not allowed here

I am trying to select values from two tables and insert them into one table and calculate the number of placements in total per year. I keep getting an error saying sequence not allowed here

DROP table placement_cal CASCADE CONSTRAINTS;

CREATE TABLE placement_cal(
    cal_id  INTEGER NOT NULL,
    year    INTEGER,
    no_of_placements INTEGER,
    CONSTRAINT  pk_cal_dim PRIMARY KEY (cal_id)
);


INSERT INTO placement_cal (
SELECT cal_id.nextval  , EXTRACT(YEAR FROM start_date) , count(placement_id)
FROM placement
group by year);

INSERT INTO placement_cal (
SELECT cal_id.nextval  , EXTRACT(YEAR FROM start_date) , count(placement_id)
FROM placement_two
group by year);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can get the reason in FAQ

The following are the cases where you can't use a sequence:

For a SELECT Statement:

  • In a WHERE clause
  • In a GROUP BY or ORDER BY clause
  • In a DISTINCT clause
  • Along with a UNION or INTERSECT or MINUS
  • In a sub-query

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...