Calling an Oracle stored procedure in Squirrel SQL

Kayeight picture Kayeight · Mar 29, 2011 · Viewed 20.7k times · Source

I was able to create a stored procedure for an Oracle database, but now I can't figure out how to run it. I'm using SQuirrel SQL and this worked to create the procedure:

CREATE OR REPLACE PROCEDURE MyProc(label IN varchar2, results OUT sys_refcursor) AS
BEGIN
OPEN results FOR
    SELECT Label, Count, Timestamp 
        FROM table1
            LEFT JOIN table2 ON table1.Name=table2.Name 
    WHERE table1.Label=label
    ORDER BY Timestamp;
END;
/

I want to be able to get and display the result set. I've tried using call MyProc('param'), but this doesn't work (wrong number of arguments error). I've searched extensively on this site and others but nothing has been useful. Please help!

Answer

Kai picture Kai · Jun 26, 2013

The following works to run a stored procedure:

begin
   procedurename;
end;
/

Yes, the slash at the end is necessary!

The begin...end; declares a PL/SQL block (Oracle-specific). The slash is the command to run the block.

/(slash)

Executes the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer.

[...]

Oracle Database Online Documentation, 10g Release 2 (10.2) / SQL*Plus® User's Guide and Reference