查询可以,但写成过程就出错。创建过程失败……
icbm 2005-11-19 07:06:41 select cnum, marc_rec_no, slib.get_item_title(marc_rec_no) as title
from
(
select cnum, marc_rec_no
from
(
select count(*) as cnum, marc_rec_no
from
(
select i.marc_rec_no
from libsys.lend_lst s, libsys.item i, libsys.marc m
where s.prop_no = i.prop_no and i.marc_rec_no = m.marc_rec_no and m.marc_type='C'
union all
select i.marc_rec_no
from libsys.lend_hist s, libsys.item i, libsys.marc m
where s.prop_no_f = i.prop_no and i.marc_rec_no = m.marc_rec_no and m.marc_type='C'
)
group by marc_rec_no
)
order by cnum desc
)
where rownum <=1000;
这个查询单独运行正常。
我想创建一个过程,把查询的结果存到另一张表中去。
create or replace procedure update_top_all
is
cursor c1 is
select cnum, marc_rec_no, slib.get_item_title(marc_rec_no) as title
from
(
select cnum, marc_rec_no
from
(
select count(*) as cnum, marc_rec_no
from
(
select i.marc_rec_no
from libsys.lend_lst s, libsys.item i, libsys.marc m
where s.prop_no = i.prop_no and i.marc_rec_no = m.marc_rec_no and m.marc_type='C'
union all
select i.marc_rec_no
from libsys.lend_hist s, libsys.item i, libsys.marc m
where s.prop_no_f = i.prop_no and i.marc_rec_no = m.marc_rec_no and m.marc_type='C'
)
group by marc_rec_no
)
order by cnum desc
)
where rownum <=1000;
begin
delete from top_all;
commit;
for r in c1 loop
insert into slib.top_all(cnum, marc_rec_no, title)
values(r.cnum, r.marc_rec_no, r.title);
end loop;
commit;
end;
结果创建过程出错:
SQL>
SQL> create or replace procedure update_top_all
2 is
3 cursor c1 is
4 select cnum, marc_rec_no, slib.get_item_title(marc_rec_no) as title
5 from
6 (
7 select cnum, marc_rec_no
8 from
9 (
10 select count(*) as cnum, marc_rec_no
11 from
12 (
13 select i.marc_rec_no
14 from libsys.lend_lst s, libsys.item i, libsys.marc m
15 where s.prop_no = i.prop_no and i.marc_rec_no = m.marc_rec_no and m.marc_type='C'
16 union all
17 select i.marc_rec_no
18 from libsys.lend_hist s, libsys.item i, libsys.marc m
19 where s.prop_no_f = i.prop_no and i.marc_rec_no = m.marc_rec_no and m.marc_type='C'
20 )
21 group by marc_rec_no
22 )
23 order by cnum desc
24 )
25 where rownum <=1000;
26 begin
27 --truncate table slib.top_all;
28 delete from top_all;
29 commit;
30
31 for r in c1 loop
32
33 insert into slib.top_all(cnum, marc_rec_no, title)
34 values(r.cnum, r.marc_rec_no, r.title);
35 end loop;
36
37 commit;
38 end;
39 /
Warning: Procedure created with compilation errors
SQL> show errors
Errors for PROCEDURE SLIB.UPDATE_TOP_ALL:
LINE/COL ERROR
-------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
23/9 PLS-00103: Encountered the symbol "ORDER" when expecting one of the following: ) , with <an identifier> <a double-quoted delimited-identifier> group having intersect minus start union where connect The symbol ")" was substituted for "ORDER" to continue.
24/5 PLS-00103: Encountered the symbol ")" when expecting one of the following: , ; for
SQL>
请大侠指点。