1

我有一个插入语句,我需要从中返回一个参数以便以后使用它。我遇到了一个奇怪的错误,我似乎无法找到解决方案。任何人都可以阐明它吗?

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 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
4

1 回答 1

7

您需要将其放入 PL/SQL 块中:

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;
于 2012-08-24T08:33:03.843 回答