Oracle INSERT into two tables in one query

前端 未结 2 1323
醉话见心
醉话见心 2020-12-28 23:45

Just wondering if it is possible to run an INSERT into two tables in a single query for Oracle 11g?

I know you can do a INSERT ALL ... SELECT query, but I need to do

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 00:19

    Try to use from dual;, like this:

    INSERT ALL
    INTO table1
      (tid, date, title) values (s_tid, s_date, s_title)
    INTO table2
      (tid, date, user, note) values (s_tid, s_date, s_user, s_note)
    SELECT s_tid, s_date, s_title, s_user, s_note
    FROM
    ( 
        SELECT 
            1 s_tid,
            '01-JAN-15' s_date,
            'title' s_title,
            'john' s_user,
            'test note' s_note
        FROM dual;
    )
    

提交回复
热议问题