0

I'm trying to execute the following statement:

INSERT INTO mySchema.ODI_PRICELIST_THREAD_TABLE
(
     src_table,
     thread_id,
     creation_date
)
    SELECT DISTINCT
           source_table AS src_table,
           num_thread_seq.nextval AS THREAD_ID,
           create_date AS CREATION_DATE
      FROM mySchema.nb_pricelist_ctrl

I need the THREAD_ID field to be a number from 1 to X where X is defined in runtime therefore I've used a sequence from 1 to X (I'm using ODI). However, I keep having the ORA-02287 Sequence not allowed error...

I've read this question and I still can't figure how I can fix my problem. I've been seaching but I'm having no luck with finding a solution. Please help

3 Answers 3

1

Keyword distinct is incompatible with sequence querying. If you really need it, try something like

INSERT INTO mySchema.ODI_PRICELIST_THREAD_TABLE (
 src_table,
 thread_id,
 creation_date)
select 
  a.src_table,
  num_thread_seq.nextval,
  a.create_date
from
  (select distinct src_table, create_date from mySchema.nb_pricelist_ctrl) a
Sign up to request clarification or add additional context in comments.

1 Comment

It isn't important. I'll add insert for disambiguity.
1

From OraFaq :

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

http://www.orafaq.com/wiki/ORA-02287

Comments

0

Try this

INSERT INTO mySchema.ODI_PRICELIST_THREAD_TABLE
(
     src_table,
     thread_id,
     creation_date
)
    SELECT DISTINCT
           source_table AS src_table,
           num_thread_seq.nextval() AS THREAD_ID,
           create_date AS CREATION_DATE
      FROM mySchema.nb_pricelist_ctrl

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.