简体   繁体   中英

Testing a function in PL/SQL Developer

This is my function:

FUNCTION GET(V_IN IN NUMBER) RETURN VARCHAR2 AS
    V_OUT VARCHAR2(1000);
BEGIN
    function body
END;

When I right click the function and click on test, I am getting the following:

begin
  -- Call the function
  :result := pkg.get(V_IN => :V_IN);
end;

How do I substitute a value for this variable V_IN? I need to test it for a number, say 940.

When I try the code:

declare
  r varchar2(2000);
begin
  -- Call the function
  r := pkg.get(940);
end;

I am getting an error:

ORA-01036: illegal variable name/number

Can you suggest various ways of calling this function?

PS: Tool used: PL/SQL Developer Allround Automations. Version 8.0.1.1502

Oracle Database 11g Enterprise Edition

Once you've clicked on your function and clicked on Test in the context menu a Test window is brought up with the code you've shown. There are two panes in this window - the top pane shows the code which PL/SQL Developer generated to invoke the function, and the lower pane contains a list of the parameters to your function. In the lower pane of the Test window there's a list of the parameters to the function with three columns - Variable, Type, and Value. Type the value you want into the Value column in the row with your parameter's name, then click on the Start Debugger button (top left of the Test window, under the 'Test Script' tab's name), then click on the Run button (immediately to the right of the Start Debugger button).

Best of luck.

"How do I substitute a value for this variable V_IN? I "

When you run the test in PLSQL Developer the bottom pane of the test window is a property list for all the substitution variables. You define the datatype and the input values (when appropriate). Output values are available in this window after the test is run.

"ORA-01036: illegal variable name/number"

Not sure what causes this. It's probably not PLSQL Developer but a bug in your function code (which you have not posted).

I was able to run the function as follows:

 declare 
     v varchar2(1000);
 begin
     select pkg.get(940) into v from dual;
     dbms_output.put_line(v);
 end;

Also, as per APC's comment, there is a property list(the small window appearing below the PL/SQL worksheet, having Variable , Type and Value fields). You need to enter the value which you wish to pass in the value field and click on Execute (shortcut-F8). The output will be shown and highlighted in yellow in the same property list window. Click below link to refer the screenshot:

Function Call with single parameter

I assume you are still in pl/sql "Test window", when you modified the original test code to your custom. Pl/sql sometimes is buggy. Open a new "SQL window" and try to run there with dbms_output.put_line() to see the result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM