Oracle insert into returning

前端 未结 1 897
旧时难觅i
旧时难觅i 2021-01-21 08:22

I\'m trying return id after insert:

CREATE SEQUENCE seq_osobne_udaje
INCREMENT BY 1 START WITH 1;

CREATE OR REPLACE TRIGGER trig_osobne_udaje_seq
BEFORE INSERT          


        
相关标签:
1条回答
  • 2021-01-21 09:01

    This script works in SQL Developer:

    DROP TRIGGER trig_osobne_udaje_seq;
    DROP SEQUENCE seq_osobne_udaje;
    DROP table osobne_udaje;
    
    create table osobne_udaje(
      id NUMBER,
      name VARCHAR2(20),
      sur  VARCHAR2(20),
      born DATE,
      is_man CHAR(1)
    )
    /
    
    CREATE SEQUENCE seq_osobne_udaje
    INCREMENT BY 1 START WITH 1;
    /
    
    CREATE OR REPLACE TRIGGER trig_osobne_udaje_seq
    BEFORE INSERT ON osobne_udaje
    FOR EACH ROW
    BEGIN
      :new.id := seq_osobne_udaje.nextval;
    END;
    /
    
    var tmp number;
    /
    
    BEGIN
      insert into osobne_udaje(name,sur,born,is_man) 
      values('Jacob','Wulp',to_date('28.07.1992','DD.MM.YYYY'),'Y')
      returning id into :tmp;
    END;
    /
    
    print tmp;
    
    0 讨论(0)
提交回复
热议问题