简体   繁体   English

在PL / SQL Developer中测试功能

[英]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? 如何用值代替此变量V_IN? I need to test it for a number, say 940. 我需要测试一个数字,例如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. PS:使用的工具:PL / SQL Developer Allround Automations。 Version 8.0.1.1502 版本8.0.1.1502

Oracle Database 11g Enterprise Edition Oracle数据库11g企业版

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. 单击函数并在上下文菜单中单击“ Test后,将显示您所显示的代码的“测试”窗口。 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. 该窗口中有两个窗格-顶部窗格显示PL / SQL Developer生成的用于调用该函数的代码,下面的窗格包含该函数的参数列表。 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 " “如何用值代替此变量V_IN?我”

When you run the test in PLSQL Developer the bottom pane of the test window is a property list for all the substitution variables. 在PLSQL Developer中运行测试时,测试窗口的底部窗格是所有替换变量的属性列表。 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" “ ORA-01036:非法变量名称/编号”

Not sure what causes this. 不知道是什么原因造成的。 It's probably not PLSQL Developer but a bug in your function code (which you have not posted). 它可能不是PLSQL Developer,而是功能代码中的错误(尚未发布)。

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). 另外,根据APC的评论,有一个属性列表(PL / SQL工作表下方显示的小窗口,具有VariableTypeValue字段)。 You need to enter the value which you wish to pass in the value field and click on Execute (shortcut-F8). 您需要在值字段中输入要传递的值,然后单击执行(快捷键-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“测试窗口”中。 Pl/sql sometimes is buggy. PL / SQL有时是错误的。 Open a new "SQL window" and try to run there with dbms_output.put_line() to see the result. 打开一个新的“ SQL窗口”,然后尝试使用dbms_output.put_line()在此处运行以查看结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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