Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception handling within a for loop (cursor)

604514May 7 2008 — edited May 7 2008
Hello, I am trying to make this code work. I get an error message that says
Error(161,1): PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: begin case declare end ..... (etc).

Here is the vital parts of the code, anyone knows why this does not work??

The problem is in these lines, that is, there is no data that match in the dyn_index_prices. If so, I want it to try the next element in the foor loop, now it crashes.
select INDEX_SEC_NO
into Index_identifier
from dyn_index_prices
where tupel.PERFMEASNAME = dyn_index_prices.INDEX_NAME || ' Index';
[\code]

Any help much appreciated!
create or replace
procedure sp_BenchmarkPosition (p_Date in DATE) AS
stock_price number;
index_price number ;
temp1 number;
temp2 number;
counter integer;
Index_identifier varchar2(50);
converter number;
Stock_identifier varchar2(50);
SEGrowthCurve1XREF varchar2(50);
Identifier_paper varchar2(50);
Portfolio_name varchar2(50);


cursor c1 is select * from ALL_INDEX_DATA;


BEGIN

delete from BenchmarkPosition;
counter := 1;

for tupel in c1 loop

select price
into stock_price
from (
SELECT price,
row_number() over (order by decode(price_type, 'TMS2000', 1, 'Performance', 2, 'MSCI', 3, 'SIX', 4, 'S&P', 5, 'Bid', 6, 'Folksam', 7, 'OM', 8, 'WM1600', 9, 'Traded', 10, 'ENC', 11) ) rn
FROM tmsdat.a_prices
WHERE tmsdat.a_prices.sec_no = tupel.secno
and price_date = p_Date
and price_type in ('TMS2000', 'Performance', 'MSCI', 'SIX', 'S&P', 'Bid', 'Folksam', 'OM', 'WM1600', 'Traded', 'ENC')
)
where rn = 1;




if tupel.cur <> 'SEK' then

select FX_RATE_INTERNAL
into converter
from FX_RATES_SEK_BASE_CURRENCY
where tupel.cur = FX_RATES_SEK_BASE_CURRENCY.PRICE_CURRENCY;

stock_price := stock_price * converter;

end if;



select INDEX_SEC_NO
into Index_identifier
from dyn_index_prices
where tupel.PERFMEASNAME = dyn_index_prices.INDEX_NAME || ' Index';



select price
into index_price
from (
SELECT price,
row_number() over (order by decode(price_type, 'TMS2000', 1, 'Performance', 2, 'MSCI', 3, 'SIX', 4, 'S&P', 5, 'Bid', 6, 'Folksam', 7, 'OM', 8, 'WM1600', 9, 'Traded', 10) ) rn
FROM tmsdat.a_prices
WHERE tmsdat.a_prices.sec_no = Index_identifier
and price_date = p_Date
and price_type in ('TMS2000', 'Performance', 'MSCI', 'SIX', 'S&P', 'Bid', 'Folksam', 'OM', 'WM1600', 'Traded')
)
where rn = 1;



select sec_short_name
into Stock_identifier
from tmsdat.a_secs where tmsdat.a_secs.sec_no = tupel.secno;


temp1 := index_price * tupel.WEIGHTSODRC;


temp2 := temp1 / stock_price;


Identifier_paper := Stock_identifier || '_' || tupel.portfolio_name || '_bench';
SEGrowthCurve1XREF := 'IR' || tupel.CUR || ' Interbank';
Portfolio_name := tupel.PORTFOLIO_NAME;

insert into BenchmarkPosition values (
'BAS',
'PositionSPEC',
'PositionSPEC',
'Position',
Identifier_paper,
Stock_identifier,
Portfolio_name,
replace(temp2,',','.'),
SEGrowthCurve1XREF,
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' '
);

EXCEPTION
WHEN NO_DATA_FOUND THEN
;

end loop;
commit;

end sp_BenchmarkPosition;
[\code]
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2008
Added on May 7 2008
6 comments
439 views