下面是我的存储过程:
create or replace procedure MarketWatchFrame1 (
acct_id in number,cust_id in number,ending_co_id in number,
industry_name in varchar2,start_date in date,starting_co_id in number,
pct_change out number,status out integer)
as
type stock_cur is ref cursor;   //定义游标变量
stock_list stock_cur;
old_mkt_cap number;
new_mkt_cap number;
symbol varchar2(15);
new_price number(8,2);
old_price number(8,2);
sec_num_out number(12);begin
if cust_id!=0 then                                    
open stock_list for
select wi_s_symb from watch_item,watch_list where wi_wl_id=wl_id and wl_c_id=cust_id;//根据不同情况打开游标变量 该条件下游标有效,能正确执行
elsif industry_name!='' then
open stock_list for                           //根据不同情况打开游标变量  该条件下竟然说游标无效,郁闷死啦~~
select s_symb
from industry,company,security
where in_name=industry_name and
co_in_id=in_id and 
co_id between starting_co_id and ending_co_id and
s_co_id=co_id;
elsif acct_id!=0 then
open stock_list for                         //根据不同情况打开游标变量   该条件下游标有效,也能正确执行
select hs_s_symb from holding_summary where hs_ca_id=acct_id;
end if;
old_mkt_cap:=0.0;
new_mkt_cap:=0.0;
pct_change:=0.0;fetch stock_list into symbol;
while stock_list%FOUND loop
select lt_price 
into    new_price
from last_trade
where lt_s_symb=symbol;select s_num_out 
into sec_num_out
from security
where s_symb=symbol;select dm_close
into  old_price
from daily_et
where dm_s_symb=symbol and dm_date=start_date;old_mkt_cap:=old_mkt_cap+sec_num_out*old_price;
new_mkt_cap:=new_mkt_cap+sec_num_out*new_price;
fetch stock_list into symbol;
end loop;if old_mkt_cap!=0 then 
pct_change:=100*(new_mkt_cap/old_mkt_cap-1);
status:=0;
else
pct_change:=0.0;
status:=412;
end if;close stock_list;
end;
/在pl/sql块中调用上述存储过程:
declare
acct_id  number(11);
cust_id  number(11);
ending_co_id  number(11);
industry_name  varchar2(50);
start_date  varchar2(15);
starting_co_id  number(11);
pct_change  number(3,2);
status  integer;
temp date;begin
acct_id:=0;
cust_id:=0;
industry_name:='Airline';
start_date:='2000-10-2';
temp:=to_date(start_date,'yyyy-mm-dd');
ending_co_id:=4300000001;
starting_co_id:=4300000500;
MarketWatchFrame1(acct_id,cust_id,ending_co_id,industry_name,temp,starting_co_id,pct_change,status);
end;执行时产生如下问题:
declare
*
第 1 行出现错误:
ORA-01001: 无效的游标
ORA-06512: 在 "MZQ.MARKETWATCHFRAME1", line 37
ORA-06512: 在 line 20
查了半天也不知道为什么!很挫人啊!求众位赐教啊~~~

解决方案 »

  1.   

    select s_symb 
    from industry,company,security 
    where in_name=industry_name and 
    co_in_id=in_id and 
    co_id between starting_co_id and ending_co_id and 
    s_co_id=co_id; 这个SQL用具体的值代替进去可以执行吗?
      

  2.   

    我用具体值查询过,能正确执行,过程如下:
    SQL> select s_symb
      2  from industry,company,security
      3  where in_name='Airline' and
      4  co_in_id=in_id and
      5  co_id between 4300000001 and 4300000500 and
      6  s_co_id=co_id;S_SYMB
    ---------------
    AWA
    BAB
    ACAI
    不知楼上是不是这个意思!
      

  3.   

    楼主一些习惯不好
    不等号建议用<>,通用性好些
    sql语句多表查询建议加上别名
    最后industry_name!=''(是空字符串吗?) 改成industry_name is not null
      

  4.   

    多谢fosjos!果然是industry_name!=''这里的问题,按fosjos的建议改为industry_name IS NOT NULL后,已能正确执行!