如何从Oracle SQL中的表1更新表2中的ID [英] How to update ID in table 2 from table 1 in Oracle sql

查看:96
本文介绍了如何从Oracle SQL中的表1更新表2中的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,第一个表具有列ID, email, password.第二个表具有id, salary, company, dept.

I have two tables, the first has columns ID, email, password. Second table has id, salary, company, dept.

表1栏ID是自动生成的数字.

Tables 1 col Id is auto-generated number.

我有一个Java表单,该表单收集ID以外的所有这些值,并使用过程保存到db.

I have a Java form that collects all these values except id and saves to db using procedure.

现在,每当我向Java表单添加详细信息时,如何将其与Java表单中的其他值一起传递给表2?

Now whenever I add details to the Java form, how can I pass it to table 2 along the other values from java form?

我尝试了insert into table2(id) select id from table1;insert into table2(salary, company) values (x, y);

如何使用SQL中的过程将这两个语句组合在一起?

How do I combine these two statement using a procedure in SQL?

推荐答案

您可以尝试这样:

create or replace procedure proc (em in varchar2,pass in varchar2,sal in number,cmp in varchar2,d in number)
as
sid number;
begin
insert into table1(id,email,password) values(<autogenerated_number>,em,pass) returning id into sid;
insert into table2(id,salary,company,dept) values(sid,sal,cmp,d);
commit;
end;

这篇关于如何从Oracle SQL中的表1更新表2中的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆