从列petit.username和从列block.regname,根据条件将数据插入到表中的列ACCEPTANCE_LINE, LINE_REVIEW, REGNAME_LINE, USERNAME_LINE中petit。
但是该表petit有很多列。
如何不指定所有这些列?例如,c.f5, c.f6, […]不需要。
create or replace procedure LINE2 is
a1 integer;
begin
for c in (
select
case when t2.regname like '%sp3%' then '5-555' end ACCEPTANCE_LINE,
case when t.username like '%sp3%' then '5-444' end LINE_REVIEW,
case when t2.regname='53' then '12345' end REGNAME_LINE,
case when t.username='53' then '123456' end USERNAME_LINE ,
t2.regname F5,t.username F6,
[…]
from petit t, block t2 where t.id=t2.id_ger and trunc(t2.date_end) > '01.01.2000'
) loop
select HIBERNATE_SEQUENCE.NEXTVAL into a1 from petit t where rownum=1;
insert into petit values(
c.ACCEPTANCE_LINE, c.LINE_REVIEW,c.REGNAME_LINE, c.USERNAME_LINE,
c.f5, c.f6, […]
);
commit;
end loop;
commit;
end LINE2;
请注明您需要什么:
永远不要在循环中插入,总是从查询中批量插入。在这种情况下,过程将如下所示:
程序中的更改不应固定。调用该过程的代码必须决定如何处理事务——提交或回滚。至少是这样的:
您可以使用仅包含要插入的所需列的插入视图。声明为
NOT NULL- 的列始终是必需的。假设有这样一个表,插入时需要填写
col1:那么一切就很简单了——通过光标填充必要的列,插入的时候,根本不需要指定任何列:
结果:
PS TC 接受的答案是他特定情况下的解决方案。这种解决方案更适合类似的任务,因为它更灵活,同时也不会降低生产力。