我寫了2個程序;
如果你可以學習你的seq名稱爲id;
create or replace procedure FOO_INSERT(foo_name in varchar2, FooTags_tagName in varchar2)
is
foo_seq_val number;
footag_seq_val number;
begin
select foo_seq.nextval into foo_seq_val from dual;
insert into foo(id,name) values (foo_seq_val, foo_name);
select footag_seq.nextval into footag_seq_val from dual;
insert into footags (id,fooid,tagName) values(footag_seq_val,foo_seq_val,FooTags_tagName);
commit;
end;
如果你不能學習你的seq名稱爲ids;
create or replace procedure FOO_INSERT_T(foo_name in varchar2, FooTags_tagName in varchar2)
is
foo_seq_val number;
begin
insert into foo_T(name) values (foo_name);
select id into foo_seq_val from FOO_T where name =foo_name;
insert into footags_T (fooid,tagName) values(foo_seq_val,FooTags_tagName);
commit;
end;
如果您通過ids;
insert into foo (id, name) values (123,'foo_name');
insert into footags (id,fooid,tagname) select 444,id, 'tag_name' from foo ;
commit;
對於第二個過程我假設你foo_T.name值是唯一的或者您的每一行的其他值讓你的ID是唯一的。您可以將您的選擇結束與and ... and ..
您可以看到一個COMMIT
每種方法。因爲如果出現錯誤,事務回滾所有插入內容爲foo_table
和fooTags_table
。這是準確性。
你想一個程序? –
@mehmetsahin如果這會在mybatis中起作用或很容易轉換?我會誠實地說,我不知道這個特定行動的最佳做法是什麼。 – canadiancreed
Foo.id和FooTags.id不是一個序列,我認爲你通過它們? –