How to SELECT inside a DECLARE block?
10:05 11 Nov 2025

Context:

As a developer in a large company, I am allowed to query (read-only) any table in the database and see the result (for debugging and investigation purposes).

When I do so (either from sqldeveloper or directly from IntelliJ or literally any app that has a scratchpad and a connection to the DB), I write some SELECT statements and see the result immediately.

But writing SELECTs is not enough : The company has a large and intricate code base of SQL functions -- which do not only contain SELECT but also have branching (if...then.. etc.). I cannot just copy-paste the queries they contain into my scratchpad!

Problem :

In order to call an SQL function, I must wrap the call in a DECLARE...BEGIN...END block, as per SQL syntax. But then, I am forced to do SELECT INTO and put the result into a variable.

Question:

How can I see the result of the DECLARE...BEGIN...END block (assuming that ultimately I'm always getting either the result of a SELECT, or a cursor) ?

============

EXAMPLE:

  -- A function from an external SQL package, which I cannot modify or maybe even see.
  function get_whatever()
  return sys_refcursor as
    v_select_cursor sys_refcursor;
  begin
    ...
  end;


  -- My own scratchpad : 
  declare
  begin
     get_whatever(); -- how do I display the result of this as easily as I would display a simple SELECT?
  end;
oracle-database plsql oracle-sqldeveloper