Oracle stored procedure has OUT parameter and returns result set, e.g.
create or replace procedure foo(empId IN NUMBER, maxSalary OUT NUMBER) AS BEGIN
select
In Oracle, you cannot run direct select statements without an INTO
clause.
If you are using Oracle 12c and above, you may use a REF CURSOR
and DBMS_SQL.RETURN_RESULT
create or replace procedure foo(empId IN NUMBER, maxSalary OUT NUMBER) AS
q SYS_REFCURSOR;
BEGIN
OPEN q FOR select * from Employee e where e.id >=empId;
DBMS_SQL.return_result (q); -- This will display the result
select max(salary) into maxSalary from Employee;
END;
For previous versions ( 11g,10g) , You could pass a REF CURSOR
as an OUT
parameter and print it from sqlplus
or TOAD by running as script.
create or replace procedure foo(empId IN NUMBER, maxSalary OUT NUMBER,
q OUT SYS_REFCURSOR) AS
BEGIN
OPEN q FOR select * from Employee e where e.id >=empId;
select max(salary) into maxSalary from Employee;
END;
Define bind variables before calling the procedure.
VARIABLE v_empID NUMBER
VARIABLE v_maxsalary NUMBER
VARIABLE v_q REFCURSOR
EXEC :v_empID := 101
EXEC foo(:v_empID,:v_maxsalary,:v_q )
PRINT v_q -- This will display the result from the query.