Hi
I am new to cursors
I have a table
SQL> select * from commodity_m_det ails;
COMMODITY_ID COMMODITY_NAME STAR END INTERVAL
-------------------- ------------------------------ ---- ---- ---------------
C1 Commodity1 1996 2006 2
C2 Commodity2 1996 2000 2
C3 Commodity3 1983 1995 4
i need to write a procedure for different years for every commodity
o/p is like
For C3
year
-----------------
1983-1986
1986-1989
1989-1992
1992-1995
i have written like this
[code=oracle]
create or replace procedure getYear(commodi tyid in varchar2,
results out resultscur.r,
status out varchar2)
is
V_data number(10);
cursor c1 is select start_year,end_ year,interval_n umber from commodity_m_det ails where commodity_id=co mmodityid;
begin
V_data:=0;
FOR record in c1
LOOP
V_data:=V_data+ (record.end_yea r-record.start_ye ar)/record.interval _number;
V_data:=record. start_year+V_da ta;
end loop;
DBMS_OUTPUT.PUT _LINE(V_data);
commit;
status:='0';
exception
when others then
status:='7';
end getYear;[/code]
/
But it is giving only 1986
please help me
Thank you
I am new to cursors
I have a table
SQL> select * from commodity_m_det ails;
COMMODITY_ID COMMODITY_NAME STAR END INTERVAL
-------------------- ------------------------------ ---- ---- ---------------
C1 Commodity1 1996 2006 2
C2 Commodity2 1996 2000 2
C3 Commodity3 1983 1995 4
i need to write a procedure for different years for every commodity
o/p is like
For C3
year
-----------------
1983-1986
1986-1989
1989-1992
1992-1995
i have written like this
[code=oracle]
create or replace procedure getYear(commodi tyid in varchar2,
results out resultscur.r,
status out varchar2)
is
V_data number(10);
cursor c1 is select start_year,end_ year,interval_n umber from commodity_m_det ails where commodity_id=co mmodityid;
begin
V_data:=0;
FOR record in c1
LOOP
V_data:=V_data+ (record.end_yea r-record.start_ye ar)/record.interval _number;
V_data:=record. start_year+V_da ta;
end loop;
DBMS_OUTPUT.PUT _LINE(V_data);
commit;
status:='0';
exception
when others then
status:='7';
end getYear;[/code]
/
But it is giving only 1986
please help me
Thank you
Comment