本文介绍了在Oracle SQL插入语句中返回参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个插入语句,我需要从中返回一个参数以便以后使用.我遇到一个奇怪的错误,似乎无法找到解决方案.任何人都可以阐明它吗?
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 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
推荐答案
您需要将其放入PL/SQL块中:
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;
这篇关于在Oracle SQL插入语句中返回参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!