+1  A: 

Have you heard of "SQuirreL SQL Client"?

http://squirrel-sql.sourceforge.net/

Thanks, have you got an example of usage?
Hamish Grubijan
For instance, how do I connect to an Oracle DB with it?
Hamish Grubijan
I've never used it but I've heard good things about it. It's java jdbc based so you'll probably have to download the Oracle jdbc drivers.
Hm ... sounds good so far; I just wish someone gave me more detailed steps.
Hamish Grubijan
+2  A: 

I am not sure how to see the actual rows/records that come back.

Stored procedures do not return records. They may have a cursor as an output parameter, which is a pointer to a select statement. But it requires additional action to actually bring back rows from that cursor.

In SQL Developer, you can execute a procedure that returns a ref cursor as follows

var rc refcursor
exec proc_name(:rc)

After that, if you execute the following, it will show the results from the cursor:

print rc
Gary
+8  A: 

Not only is there a way to do this, there is more than one way to do this (which I concede is not very Pythonic, but then SQL*Developer is written in Java ).

I have a procedure with this signature: get_maxsal_by_dept( dno number, maxsal out number).

I highlight it in the SQL*Developer Object Navigator, invoke the right-click menu and chose Run. (I could use ctrl+F11.) This spawns a pop-up window with the following generated test harness:

DECLARE
  DNO NUMBER;
  MAXSAL NUMBER;
BEGIN
  DNO := NULL;

  GET_MAXSAL_BY_DEPT(
    DNO => DNO,
    MAXSAL => MAXSAL
  );
  DBMS_OUTPUT.PUT_LINE('MAXSAL = ' || MAXSAL);
END;

I set the variable DNO to 50 and press okay. In the Running - Log pane (bottom right-hand corner unless you've closed/moved/hidden it) I can see the following output:

Connecting to the database apc.
MAXSAL = 4500
Process exited.
Disconnecting from the database apc. 

To be fair the runner is less friendly for functions which return a Ref Cursor, like this one: get_emps_by_dept (dno number) return sys_refcursor.

DECLARE
  DNO NUMBER;
  v_Return sys_refcursor;
BEGIN
  DNO := 50;

  v_Return := GET_EMPS_BY_DEPT(
    DNO => DNO
  );
  -- Modify the code to output the variable
  -- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;

However, at least it offers the chance to save any changes to file, so we can retain our investment in tweaking the harness...

DECLARE
  DNO NUMBER;
  v_Return sys_refcursor;
  v_rec emp%rowtype;
BEGIN
  DNO := 50;

  v_Return := GET_EMPS_BY_DEPT(
    DNO => DNO
  );

  loop
    fetch v_Return into v_rec;
    exit when v_Return%notfound;
    DBMS_OUTPUT.PUT_LINE('name = ' || v_rec.ename);
  end loop;
END;

The output from the same location:

Connecting to the database apc.
name = TRICHLER
name = VERREYNNE
name = FEUERSTEIN
name = PODER
Process exited.
Disconnecting from the database apc. 

Alternatively we can use the old SQL*PLus commands in the SQL*Developer worksheet:

var rc refcursor 
exec :rc := get_emps_by_dept(30) 
print rc

In that case the output appears in Script Output pane (default location is the tab to the right of the Results tab).

The very earliest versions of the IDE did not support much in the way of SQL*Plus. However, all of the above commands have been supported since 1.2.1. Refer to the matrix in the online documentation for more info.


"When I type just var rc refcursor; and select it and run it, I get this error (GUI):"

There is a feature - or a bug - in the way the worksheet interprets SQL*Plus commands. It presumes SQL*Plus commands are part of a script. So, if we enter a line of SQL*Plus, say var rc refcursor and click Execute Statement (or F9 ) the worksheet hurls ORA-900 because that is not an executable statement i.e. it's not SQL . What we need to do is click Run Script (or F5 ), even for a single line of SQL*Plus.


"I am so close ... please help."

You program is a procedure with a signature of five mandatory parameters. You are getting an error because you are calling it as a function, and with just the one parameter:

exec :rc := get_account(1)

What you need is something like the following. I have used the named notation for clarity.

var ret1 number
var tran_cnt number
var msg_cnt number
var rc refcursor

exec :tran_cnt := 0
exec :msg_cnt := 123

exec get_account (Vret_val => :ret1, 
                  Vtran_count => :tran_cnt, 
                  Vmessage_count => :msg_cnt, 
                  Vaccount_id   => 1,
                  rc1 => :rc )

print tran_count 
print rc

That is, you need a variable for each OUT or IN OUT parameter. IN parameters can be passed as literals. The first two EXEC statements assign values to a couple of the IN OUT parameters. The third EXEC calls the procedure. Procedures don't return a value (unlike functions) so we don't use an assignment syntax. Lastly this script displays the value of a couple of the variables mapped to OUT parameters.

APC
I am not sure if I have SQL*Plus feature installed. How would I check if I have it?
Hamish Grubijan
@HamishGrubijan - the simplest way of checking would be to fire up a command line window and type `sqlplus`
APC
So ... when I type sqlplus on command line (cmd.exe), it asks me for a password - it is there. However, when I type this command by itself: `var rc refcursor;` it complains about it. I guess this is because I am not in SQL*Plus Developer Worksheet ... so, how do I get there?
Hamish Grubijan
@HamishGrubijan - Which version of SQL*Dev are you using? VAR was not supported prior to 1.2.1
APC
Version 1.5.5 Build MAIN-5969 | CVS Version Internal to Oracle SQL Developer (client-only) | Java(TM) Platform 1.5.0_06 | Oracle IDE 1.5.5.59.69 | Versioning Support 1.5.5.59.69. I could do more updates, but this is > 1.2.1, so it should be recent enough.
Hamish Grubijan
@HamishGrubijan - should be recent enough indeed. So, when you say "it complains about it" what complains? And how does it do so? Remote diagnosis is tough at the best times. So the more precise details the better.
APC
@APC, please see my edit.
Hamish Grubijan
Btw, I posted bounty.
Hamish Grubijan
@HamishGrubjian - I have edited my response with what I think may be the solution to your problem.
APC
+150 points. Please address my final edit for the additional 25 (I think) pts bonus.
Hamish Grubijan
I have problems running this with both F5 and F9. Which one should I use? What did you mean by positional notation? Should I be removing spaces and new lines?
Hamish Grubijan
@HamishGrubijan - F5 to run the whole script, F9 to execute a single statement. So what problems are you having? Alas, telepathy and remote viewing are not amongst my skills.
APC
Thanks for the patience; I did add yet another edit at the bottom of the question.
Hamish Grubijan
@HamishGrubijan - that error is due to a typo in my posted example. References to SQL*Plus variables need a colon in front of them. So it should have been `:rc` not `rc`. Apologies.
APC
Booya! I wish ORA error messages were more helpful. Feel free to add `print :rc`, `print :tran_count` to the answer to make it more helpful to those who find it later. I'll add it as well (to my question).
Hamish Grubijan
@HamishGrubijan - if it's any consolation you are far from being the first to be bamboozled by Oracle's error messages. Some of them are very oblique indeed. Anyway, at least we goot there in the end!
APC
+2  A: 

My recommendation is TORA

Sujee
I thought TORA had died a few years back. Nice to see somebody has resuscitated it.
APC
I don't think so. I am using it everyday at work for last 1 year. Initially had some crashes but now works well after few updates. Switched to TORA after dissatisfied with "TOAD freeware" and memory hog "SQL developer".
Sujee
What features does it not have which SQL Developer does?
Hamish Grubijan
I am also interested in the converse.
Hamish Grubijan
A: 

There are two possibilities, both from Quest Software, TOAD & SQL Navigator:

Here is the TOAD Freeware download: http://www.toadworld.com/Downloads/FreewareandTrials/ToadforOracleFreeware/tabid/558/Default.aspx

And the SQL Navigator (trial version): http://www.quest.com/sql-navigator/software-downloads.aspx

MatthieuF
Any examples using TOAD for what I want to do?
Hamish Grubijan