在1个PL / SQL块中,必须使用多个SELECT
查询和一个块语句。在此block语句中,我们必须在进行insert
查询之前进行计数,并且一旦insert
语句运行之后,之后必须进行其后述的id值的after_counts。
set heading off
set colsep '|'
set feedback off
set sqlformat csv
set trimspool on
spool output.txt
declare
ln_rec tab1%rowtype;
lv varchar(20);
sid tab.id%type;
b_cnts number;
a_cnts number;
type sh_id is varray(10) of tab.col1%type;
id sh_id := sh_id(1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
begin
select a.id, count(b.sub_id) into sid, b_cnts as "before_counts" from tab a, tab1 b;
for i in (select distinct b.sub_id from tab a, tab1 b where a.id in (1, 3, 5, 7, 9, 11, 13, 15, 17, 19))
loop
select * into ln_rec from tab1 where sub_id = i.sub_id;
insert into new_tab values(id, i.sub_id, lv);
commit;
end loop;
select a.id, count(b.sub_id) into sid, a_cnts as "after_counts" from tab a, tab b;
end;
spool off
但是当我执行它时,由于上面的SET system variable summary
和由于insert
而在id
语句中出现了错误。我想要以csv格式或输出格式输出,例如应生成3列作为id,before_counts,after_counts及其正确值。像这样:-
<id> <before_counts> <after_counts> -- This heading should not appear because above used heading off
1 135 138
3 246 250
5 298 302
7 389 399
.........
答案 0 :(得分:0)
类似这样的东西:
venue