oracle insert into

qq_36943132 2018-09-04 12:54:29
oracle写个存储过程,往一个表中加数据,数据的部分字段是从另一个表来的,还有部分字段是入参进去的,这个存储过程要怎么写
...全文
708 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wandier 2018-09-17
  • 打赏
  • 举报
回复
可以批量的话,就批量插入,油标是效率低
  • 打赏
  • 举报
回复
你给点东东出来啊。
r如果一部分来自其它表,加个游标。

create or replace pro_t1 (in_1 varchar2,in_2 varchar2) is
begin
declare
cursor cur_t1 is select m1,m2 from t2 where m1=1;
type_t1 cur_t1%rowtype;
begin
open cursor cur_t1
fetch cur_t1 into type_t1;
insert into t2 (p1,p2,p3,p4) values (type_t1.m1,type_t1.m2,in_1,in_2);
close cur_t1;
end;
end ;
Mricoo_周 2018-09-04
  • 打赏
  • 举报
回复
declare
TYPE dq_row IS TABLE OF dq_tmbh%ROWTYPE;
data1 dq_row;

cursor dq_cs is
select id as tmbh from dqzb_20170810 ;

begin
open dq_cs;
loop
fetch dq_cs bulk collect into data1 limit 1000;
if data1.COUNT > 0 then
forall i in data1.first .. data1.last
insert into dq_tmbh values data1(i);
commit;
end if;
exit when dq_cs%notfound;
end loop;
end;

给你个insert模板,相应的改一下就可以
minsic78 2018-09-04
  • 打赏
  • 举报
回复
引用 2 楼 qq_36943132 的回复:
[quote=引用 1 楼 minsic78 的回复:]
这能玩出什么花来么……

insert into xxx select yyy字段1,yyy字段2...参数1,参数2... from yyy where zzz...
这样不对的 我问了是用游标
[/quote]

insert就两种样子:一种就是前面写的,一种就insert into xxx values (.....); 看着办吧~
qq_36943132 2018-09-04
  • 打赏
  • 举报
回复
引用 1 楼 minsic78 的回复:
这能玩出什么花来么……

insert into xxx select yyy字段1,yyy字段2...参数1,参数2... from yyy where zzz...
这样不对的 我问了是用游标
minsic78 2018-09-04
  • 打赏
  • 举报
回复
这能玩出什么花来么……

insert into xxx select yyy字段1,yyy字段2...参数1,参数2... from yyy where zzz...

3,499

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧