0

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.

1
  • 1
    You need to add a return parameter to your procedure. A sys refcursor would do. then call the procedure and return the result
    – kevinskio
    Commented Dec 30, 2019 at 15:32

1 Answer 1

1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.