有这样一条语句:
insert into tableA select .... from tableB returning f_id into v_id;
返回插入那一行最后的主键值,但为什么这条语句报错呢??

解决方案 »

  1.   

    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.
      

  2.   

    这种情况是可以的,但是源如果是select 语句的话就报sql命令没有正确结束。
      

  3.   

    用什么接受?我用v_id变量存储这个值啊,用于下一次查询用。
      

  4.   

    oracle只有:insert into ... values ... returning into ...而没有你写的:
    insert into table select ... from ... returning into ...
      

  5.   

    遇到这种情况用序列如何处理?
    insert into tableB select .... from .... 
    v_id := tableBseq.currentval
    ??
    这样写可以吗?
      

  6.   

    那就像sleepzzzzz写的那样好了。
      

  7.   

    insert into ... values ... returning into ... 操作一条记录,允许returning insert into table select ... from ... returning into ...  可能操作多条记录,你想让系统return哪个呢。呵呵。