I'm looking for a good explanation on how to test an Oracle stored procedure in SQL Developer or Embarcardero Rapid XE2. Thank you.
With a cursor variable, you simply pass the reference to that cursor. To declare a cursor variable, you use the REF CURSOR is the data type. PL/SQL has two forms of REF CURSOR typeS: strong typed and weak typed REF CURSOR . The following shows an example of a strong REF CURSOR .
A ref cursor is a variable, defined as a cursor type, which will point to, or reference a cursor result. The advantage that a ref cursor has over a plain cursor is that is can be passed as a variable to a procedure or a function.
Something like
create or replace procedure my_proc( p_rc OUT SYS_REFCURSOR ) as begin open p_rc for select 1 col1 from dual; end; / variable rc refcursor; exec my_proc( :rc ); print rc;
will work in SQL*Plus or SQL Developer. I don't have any experience with Embarcardero Rapid XE2 so I have no idea whether it supports SQL*Plus commands like this.
Something like this lets you test your procedure on almost any client:
DECLARE v_cur SYS_REFCURSOR; v_a VARCHAR2(10); v_b VARCHAR2(10); BEGIN your_proc(v_cur); LOOP FETCH v_cur INTO v_a, v_b; EXIT WHEN v_cur%NOTFOUND; dbms_output.put_line(v_a || ' ' || v_b); END LOOP; CLOSE v_cur; END;
Basically, your test harness needs to support the definition of a SYS_REFCURSOR
variable and the ability to call your procedure while passing in the variable you defined, then loop through the cursor result set. PL/SQL does all that, and anonymous blocks are easy to set up and maintain, fairly adaptable, and quite readable to anyone who works with PL/SQL.
Another, albeit similar way would be to build a named procedure that does the same thing, and assuming the client has a debugger (like SQL Developer, PL/SQL Developer, TOAD, etc.) you could then step through the execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With