I'm pretty sure that these calculations can be done inside one select statement with no need to create an extra cursor. But, if you still want it, I'll show you one possible example how to achieve that.
First, you have to declare an object TYPE. (It will represent a row in the result query):
create or replace type MY_TYPE as object (
name varchar2(64),
surname varchar2(64),
calculatedValue varchar2(64) --your calculated column. You may add as many columns as needed, but for simplicity, I'll stick to only one column
);
Now, create a nested table of MY_TYPE objects (it will represent the whole result set):
create or replace type MY_TYPE_LIST as table of MY_TYPE;
Now you're ready to write a pipeline function to return the result set you want.
create or replace function MY_FUNC return MY_TYPE_LIST pipelined as
cursor cur is
select name, surname from employees;
name varchar2(64);
surname varchar2(64);
calculatedColumn varchar2(64);
begin
open cur;
loop
fetch cur into name, surname;
exit when cur%notfound;
--do something here, calculate new columns
calculatedColumn := ...; --assign a value you want
pipe row (MY_TYPE(name, surname, calculatedColumn)); --the moment of truth. Pipe a row containing the new column
end loop;
end;
This function will return a new cursor containing values of MY_TYPE object.
selectstatement, and return it as usual. - Pavel Smirnov