create or replace procedure PRONAME(
USER_ID NUMBER
}
as
begin
insert into A (field1,field2) values (1,??这里该怎么写?)
end;
或者能不能先在存储过程中设一个临时变量temp,把B表中user_id=111的field2的值先赋给temp,然后再insert into A (field1,field2) values (1,temp)?
7 个解决方案
#1
create or replace procedure PRONAME(
USER_ID NUMBER
)
as
DECLARE
TEMBL B.FIELD2%TYPE;
BEGIN
SELECT FIELD2 INTO TEMBL FROM B WHERE USER_ID=111;
INSERT INTO A (FIELD1,FIELD2) VALUES(1,TEMBL);
END PRONAME;
USER_ID NUMBER
)
as
DECLARE
TEMBL B.FIELD2%TYPE;
BEGIN
SELECT FIELD2 INTO TEMBL FROM B WHERE USER_ID=111;
INSERT INTO A (FIELD1,FIELD2) VALUES(1,TEMBL);
END PRONAME;
#2
insert into a ( field1, field2) select 1, field2 from b where user_id=lll ;
#3
可以先设置一个临时变量temp。
select field2 into temp from B where user_id=111
insert into A (field1,field2) values(1,temp)
commit
直接写成insert语句也可以。
insert into A(field1,field2) select field1,field2 from B where user_id=111
select field2 into temp from B where user_id=111
insert into A (field1,field2) values(1,temp)
commit
直接写成insert语句也可以。
insert into A(field1,field2) select field1,field2 from B where user_id=111
#4
insert into A (field1,field2) values
(
select 1,b.field2 from b
where b.user_id=111
)
(
select 1,b.field2 from b
where b.user_id=111
)
#5
学习
#6
penghwa(子曰) 写的完全正确!
#7
修改
insert into a ( field1, field2)
values(1, (select field2 from b where user_id=lll)) ;
insert into a ( field1, field2)
values(1, (select field2 from b where user_id=lll)) ;
#1
create or replace procedure PRONAME(
USER_ID NUMBER
)
as
DECLARE
TEMBL B.FIELD2%TYPE;
BEGIN
SELECT FIELD2 INTO TEMBL FROM B WHERE USER_ID=111;
INSERT INTO A (FIELD1,FIELD2) VALUES(1,TEMBL);
END PRONAME;
USER_ID NUMBER
)
as
DECLARE
TEMBL B.FIELD2%TYPE;
BEGIN
SELECT FIELD2 INTO TEMBL FROM B WHERE USER_ID=111;
INSERT INTO A (FIELD1,FIELD2) VALUES(1,TEMBL);
END PRONAME;
#2
insert into a ( field1, field2) select 1, field2 from b where user_id=lll ;
#3
可以先设置一个临时变量temp。
select field2 into temp from B where user_id=111
insert into A (field1,field2) values(1,temp)
commit
直接写成insert语句也可以。
insert into A(field1,field2) select field1,field2 from B where user_id=111
select field2 into temp from B where user_id=111
insert into A (field1,field2) values(1,temp)
commit
直接写成insert语句也可以。
insert into A(field1,field2) select field1,field2 from B where user_id=111
#4
insert into A (field1,field2) values
(
select 1,b.field2 from b
where b.user_id=111
)
(
select 1,b.field2 from b
where b.user_id=111
)
#5
学习
#6
penghwa(子曰) 写的完全正确!
#7
修改
insert into a ( field1, field2)
values(1, (select field2 from b where user_id=lll)) ;
insert into a ( field1, field2)
values(1, (select field2 from b where user_id=lll)) ;