Insert Into Returning Sequence fails with ORA 02287 sequence not allowed
Dino2dyOct 18 2012 — edited Oct 19 2012Hi I work with a Oracle Database and c# with Visual Studios and I use a OLEDBADAPTER.
I have the following sql command
oleComd.CommandText = "Insert into OBJEKTI" +
"(NAZIV_OBJEKTA, SIFRA_MJESTA, SIFRA_REGION)" + " Values(:naziv, :mjesto, :region) RETURNING OBJEKAT_ID_SEQ.CURRVAL INTO :id";
But it fails with error ORA02287 sequence not allowed here. If I separate it with 2 commands insert into and then select OBJEKAT_ID_SEQ.CURRVAL from DUAL I still get the same or similar error.
But I have a sequence and trigger created so I don't understand what I am doing wrong as the trigger is set to fire before insert
create or replace
TRIGGER "OBJEKTI_ID_TRIG"
BEFORE INSERT ON "OBJEKTI"
FOR EACH ROW
DECLARE
-- Declare constants and variables in this section.
-- Example: <Variable Identifier> <DATATYPE>
-- <Variable Identifier> CONSTANT <DATATYPE>
-- varEname VARCHAR2(40);
-- varSalary CONSTANT NUMBER:=1000;
-- varSalaryDiff NUMBER;
-- invalid_salary EXCEPTION;
BEGIN
SELECT OBJEKAT_ID_SEQ.NEXTVAL
INTO :NEW.OBJEKAT_ID
FROM DUAL;
END;
And I use the same connection when doing the insert and select or returning (neither works so...). I have posted this question on 3 different forums and have gotten no reply so please help