Reputation: 265
I have a 'person' table with two fields 'person_name' and 'person_age'.
i want write a procedure that return sys_refcursor but calculating a extra field 'is_old'. por example:
PROCEDURE people_load(p_name IN VARCHAR2, P_RESULT OUT SYS_REFCURSOR) IS
BEGIN
DECLARE
isOld BOOLEAN := false;
CURSOR cursorTemp IS SELECT person_name, person_age, is_old
WHERE person_name = p_name;
BEGIN
FOR _p IN cursorTemp
LOOP
IF _p.person_age > 75 THEN
_p.is_old:=TRUE;
END IF;
END LOOP;
¿¿P_RESULT:=cursorTemp; //open P_RESULT for (open cursorTemp);??
END;
END people_load;
i dont know how to assign temporal cursor 'cursorTemp' to OUT param 'P_RESULT' to returning the result.
Upvotes: 0
Views: 1633
Reputation: 112352
You should do the calculation in the select.
CURSOR cursorTemp IS
SELECT
person_name,
person_age,
CASE WHEN person_age>75 THEN 1 ELSE 0 END AS is_old
WHERE person_name = p_name;
Upvotes: 0
Reputation: 13496
BOOLEAN
in SQL, only in PL/SQL.I suggest you calculate the is_old within the cursor. I changed it to contain 1 (true) or 0 (false).
PROCEDURE people_load(p_name IN VARCHAR2, P_RESULT OUT SYS_REFCURSOR) IS
BEGIN
DECLARE
CURSOR cursorTemp IS SELECT person_name, person_age, case when person_age > 75 then 1 else 0 end is_old
WHERE person_name = p_name;
BEGIN
P_RESULT := cursorTemp; //open P_RESULT for (open cursorTemp);
END;
END people_load;
Upvotes: 2