Home » SQL & PL/SQL » SQL & PL/SQL » ORA-02287: sequence number not allowed here
icon9.gif  ORA-02287: sequence number not allowed here [message #157473] Thu, 02 February 2006 11:29 Go to next message
Fooman
Messages: 17
Registered: April 2005
Location: Germany
Junior Member
Hi,

can anyone help. I keep on getting this error message when adding sequence to this INSERT script. the SELECT statement works when its executed on its own, with out the sequence. I've included the codes and the error message

DROP SEQUENCE CUSTOMERID;
CREATE SEQUENCE CUSTOMERID INCREMENT BY 1 START WITH 100;

INSERT INTO CUSTOMER  (CUSTOMER_ID, NAME,  STATE, Salesperson_Id, Credit_Limit )
SELECT  CUSTOMERID.nextval
	, yy.old_id
        , zz.location_code
        , zz.EMPLOYEE_ID
        , yy.credit_limit
FROM   test_all_orders4 yy JOIN 
       (SELECT e.EMPLOYEE_ID
	 		   , d.LOCATION_ID
               , l.location_code
        FROM   EMPLOYEE e
               , DEPARTMENT d,
               (SELECT location_id, location_code
               FROM    LOCATION JOIN region
               ON sales_region = regional_group) l
        WHERE  e.department_id = d.DEPARTMENT_ID
        AND    d.location_id = l.location_id
        AND    d.NAME = 'SALES'
        AND e.EMPLOYEE_ID IN (SELECT DISTINCT t.MANAGER_ID FROM EMPLOYEE t)) zz
ON SUBSTR(yy.old_id,1,2) = zz.location_code
AND yy.customer_id IS NULL
GROUP BY yy.old_id, yy.credit_limit, zz.EMPLOYEE_ID, zz.location_code;


ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 8
ORA-02287: sequence number not allowed here
Re: ORA-02287: sequence number not allowed here [message #157479 is a reply to message #157473] Thu, 02 February 2006 12:39 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
Please DESCribe your CUSTOMER table for us. I hope you are not letting Oracle implicitly convert a NUMBER to a character string.
Re: ORA-02287: sequence number not allowed here [message #157483 is a reply to message #157473] Thu, 02 February 2006 13:27 Go to previous messageGo to next message
scottwmackey
Messages: 515
Registered: March 2005
Senior Member
First off, I am pretty sure that your problem occurs because you are trying to use NEXTVAL and GROUP BY in the same level of the select. Just convert your select into an in-line view and put the NEXTVAL outside of it. By the way, you run into the same type of problem if you try to ORDER BY while using NEXTVAL.
INSERT INTO CUSTOMER  (CUSTOMER_ID, NAME,  STATE, Salesperson_Id, Credit_Limit )
SELECT CUSTOMERID.nextval
	     , old_id
       , location_code
       , EMPLOYEE_ID
       , credit_limit
FROM   (SELECT  yy.old_id
                , zz.location_code
                , zz.EMPLOYEE_ID
                , yy.credit_limit
        FROM   test_all_orders4 yy JOIN 
               (SELECT e.EMPLOYEE_ID
        	 		   , d.LOCATION_ID
                       , l.location_code
                FROM   EMPLOYEE e
                       , DEPARTMENT d,
                       (SELECT location_id, location_code
                       FROM    LOCATION JOIN region
                       ON sales_region = regional_group) l
                WHERE  e.department_id = d.DEPARTMENT_ID
                AND    d.location_id = l.location_id
                AND    d.NAME = 'SALES'
                AND e.EMPLOYEE_ID IN (SELECT DISTINCT t.MANAGER_ID FROM EMPLOYEE t)) zz
        ON SUBSTR(yy.old_id,1,2) = zz.location_code
        AND yy.customer_id IS NULL
        GROUP BY yy.old_id, yy.credit_limit, zz.EMPLOYEE_ID, zz.location_code);

I think, however, that your statement would be much easier to work with if you get rid of all of the unnecessary in-lining. And pick one style and stay with it. Don't go back and forth between using comma separated table and JOIN-ON syntax.
SELECT customerid.NEXTVAL,
       old_id,
       location_code,
       employee_id,
       credit_limit
FROM   (SELECT yy.old_id,
               l.location_code,
               e.employee_id,
               yy.credit_limit
        FROM   employee e
        JOIN   test_all_orders4 yy ON  substr(yy.old_id, 1, 2) = l.location_code
                                   AND yy.customer_id IS NULL
        JOIN   department d ON  d.department_id = e.department_id
                            AND d.NAME = 'SALES'
        JOIN   location l ON l.location_id = d.location_id 
        JOIN   region ON sales_region = regional_group
        WHERE  e.employee_id IN (SELECT DISTINCT t.manager_id FROM employee t)
        GROUP  BY yy.old_id, yy.credit_limit, e.employee_id, l.location_code);

[Updated on: Thu, 02 February 2006 13:29]

Report message to a moderator

icon10.gif  Re: ORA-02287: sequence number not allowed here [message #157612 is a reply to message #157483] Fri, 03 February 2006 09:33 Go to previous message
Fooman
Messages: 17
Registered: April 2005
Location: Germany
Junior Member
Hi thanks for both reply... much appriciated. yes you are right: Sequence cant be use in a group by function... so i had to create a temp_table and do the insert with the sequence that way.

thx again Embarassed
Previous Topic: Insert a image file to oracel db through sql query
Next Topic: SQL Query
Goto Forum:
  


Current Time: Wed Oct 15 16:55:56 CDT 2025