How to create a simple SELECT statement as a stored procedure in PL/SQL? – Regardless of the best practises around Stored Procs

oracleplsql

Was wondering how to create a simple select statement to return all records within a table in PL/SQL such as

CREATE OR REPLACE PROCEDURE getStudents
AS
C1 SYS_REFCURSOR;
BEGIN
OPEN C1 FOR
SELECT * FROM STUDENTS
DBMS_SQL.RETURN_RESULT(C1);
END;

I'm a beginner to this, Thanks in advance.

Best Answer

So what is your question? You posted your answer already:

CREATE OR REPLACE PROCEDURE getStudents
AS
C1 SYS_REFCURSOR;
BEGIN
OPEN C1 FOR
SELECT * FROM DUAL;
DBMS_SQL.RETURN_RESULT(C1);
END;
/

Procedure created.

SQL> exec getStudents

PL/SQL procedure successfully completed.

ResultSet #1

D
-
X

SQL>