1

I have an insert statement which I need to return a parameter from in order to use it later. I'm getting a strange error which I can't seem to find a solution for. Can anyone shed any light on it?

set define off;
variable videoID number;

insert into VM_VIDEO (VIDEO_ID, ...)
  values (SEQ_VMMIGVIDEO_ID.NEXTVAL, ...)
  returning VIDEO_ID into :videoID;

insert into IMAGES (IMAGE_ID, ...)
  values (SEQ_IMAGE_ID.NEXTVAL, ...);

update VM_VIDEO
  set THUMB_IMAGE_ID = SEQ_IMAGE_ID.CURRVAL
  where VIDEO_ID = :videoID;

Error:

Error starting at line 4 in command:
insert into VM_VIDEO (VIDEO_ID, ...) values (SEQ_VMMIGVIDEO_ID.NEXTVAL, ...) returning VIDEO_ID into :videoID
Error report:
SQL Error: Not all return parameters registered
1
  • A SQL*Plus variable may not work here. Try a PL/SQL variable (DECLARE). Commented Aug 24, 2012 at 8:30

1 Answer 1

7

You need to put it into a PL/SQL block:

declare
  videoID number;
begin
  insert into VM_VIDEO (VIDEO_ID, ...)
    values (SEQ_VMMIGVIDEO_ID.NEXTVAL, ...)
    returning VIDEO_ID into videoID;

  insert into IMAGES (IMAGE_ID, ...)
    values (SEQ_IMAGE_ID.NEXTVAL, ...);

  update VM_VIDEO
    set THUMB_IMAGE_ID = SEQ_IMAGE_ID.CURRVAL
    where VIDEO_ID = videoID;
end;
Sign up to request clarification or add additional context in comments.

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.