SQL> drop table test ;Table dropped.SQL> create table test ( today) as select sysdate from dual where 1= 2 ;Table created.SQL> set serveroutput on SQL> declare 2 3 v_today date ; 4 begin 5 6 insert into test values (sysdate) return today into v_today ; 7 commit; 8 dbms_output.put_line(v_today); 9 end; 10 / 19-MAY-04PL/SQL procedure successfully completed.
这种情况是可以的,但是源如果是select 语句的话就报sql命令没有正确结束。
用什么接受?我用v_id变量存储这个值啊,用于下一次查询用。
oracle只有:insert into ... values ... returning into ...而没有你写的: insert into table select ... from ... returning into ...
遇到这种情况用序列如何处理? insert into tableB select .... from .... v_id := tableBseq.currentval ?? 这样写可以吗?
那就像sleepzzzzz写的那样好了。
insert into ... values ... returning into ... 操作一条记录,允许returning insert into table select ... from ... returning into ... 可能操作多条记录,你想让系统return哪个呢。呵呵。
SQL> declare
2
3 v_today date ;
4 begin
5
6 insert into test values (sysdate) return today into v_today ;
7 commit;
8 dbms_output.put_line(v_today);
9 end;
10 /
19-MAY-04PL/SQL procedure successfully completed.
insert into table select ... from ... returning into ...
insert into tableB select .... from ....
v_id := tableBseq.currentval
??
这样写可以吗?