Declare
type v_year_arr is varray(100) of emps%rowtype;
v_deptid emps.department_id%type :=90;
v_rem1 number(5,2);
v_rem2 number(5,2);
v_rem3 number(5,2);
v_year v_year_arr;
Begin
select * bulk collect into v_year from emps where department_id = v_deptid;
v_rem1 := MOD(v_year.yof,4);
v_rem2 := MOD(v_year.yof,100);
v_rem3 := MOD(v_year.yof,400);
for i..v_year loop
If (v_rem1=0 and v_rem2=0 and v_rem3=0)
then
DBMS_OUTPUT.PUT_LINE('Leap year :'||v_year.yof);
else
DBMS_OUTPUT.PUT_LINE('Not a Leap year :'||v_year.yof)
End if;
end loop;
end;
Asked
Active
Viewed 55 times
-2

Nick Krasnov
- 26,886
- 6
- 61
- 78
-
1Please explain what is "v_year.yof". – alexs Aug 08 '13 at 12:37
-
1Please edit your question and include additional information such as the exact text of the error message, an indication of which line is being flagged, etc. Thanks. – Bob Jarvis - Слава Україні Aug 08 '13 at 12:58
1 Answers
2
I think you'd be better off writing this using a cursor FOR loop, as in:
Declare
v_deptid emps.department_id%type :=90;
v_rem1 number(5,2);
v_rem2 number(5,2);
v_rem3 number(5,2);
Begin
FOR aRow IN (select * from emps where department_id = v_deptid)
LOOP
v_rem1 := MOD(aRow.yof,4);
v_rem2 := MOD(aRow.yof,100);
v_rem3 := MOD(aRow.yof,400);
If (v_rem1=0 and v_rem2<>0) or (v_rem2=0 and v_rem3=0) then
DBMS_OUTPUT.PUT_LINE('Leap year :'||aRow.yof);
else
DBMS_OUTPUT.PUT_LINE('Not a Leap year :'||aRow.yof)
End if;
end loop;
end;
This eliminates the potential problem of having more than 100 rows returned by the SELECT...BULK COLLECT INTO...
statement. I also took the liberty of correcting your leap year determination.
Share and enjoy.

Bob Jarvis - Слава Україні
- 48,992
- 9
- 77
- 110