Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
create or replace function open_cursor (query_in varchar2) return sys_refcursor is
c sys_refcursor;
begin
open c for query_in;
return c;
end;
/
Function created.
set serveroutput on
declare
foo sys_refcursor;
y s_emp%rowtype;
begin
foo := open_cursor('select * from s_emp order by last_name, first_name');
loop
fetch foo into y;
exit when foo%notfound;
dbms_output.put_line(y.last_name||', '||y.first_name);
end loop;
end;
/
Biri, Ben
Catchpole, Antoinette
Chang, Eddie
Dancs, Bela
Dumas, Andre
PL/SQL procedure successfully completed.
SQL> VAR A REFCURSOR
SQL> EXEC :A := open_cursor('SELECT 1 FROM DUAL')
PL/SQL procedure successfully completed.
SQL> PRINT A
1
----------
1
You refer to "mytestProc SP" (a stored procedure), you say that it returns "pResult" (as though it was a function), yet "pResult" does not appear in your parameter/argument list (which is the way by which you can return a value from a procedure), so I don't see how a stored procedure can be "returning the pResult" if it is not listed as an "out" parameter.Davism said:The mytestProc SP in this example is taking in 2 parameters (ptestval1, and ptestval2) and returning the pResult.
CREATE OR REPLACE FUNCTION foo (arg1 number, arg2 varchar2)
RETURN <whatever> IS
ptestval1 number;
ptestval2 varchar2;
retval1 number;
BEGIN
...
mytestProc (ptestval1, ptestval2, retval1);
...
END;
/
IMonth := to_char(pdtInDate,'MM');
I don't quite follow your use of "Except", above. Your "pdtIntDate" expression must be a DATE expression for the TO_CHAR function to derive the character equivalent of the Month number; "IMonth" should be a character data type (although "IMonth" can also be NUMBER since Oracle will perform an automatic Character-to-Number conversion from a TO_CHAR function to a NUMBER receiving data item.)Davism said:Except for IMonth is a CHAR value and pdtIntDate is a DATE value.