gpt4 book ai didi

oracle - 在 SQL Developer 中运行存储过程?

转载 作者:行者123 更新时间:2023-12-03 05:19:27 24 4
gpt4 key购买 nike

我正在尝试运行一个具有多个输入和输出参数的存储过程。该过程只能通过导航在我的“连接”面板中查看

Other Users | <user> | Packages | <package> | <procedure>

如果我右键单击,菜单项是“按...排序成员”和“创建单元测试”(灰显)。当用户访问该过程时,似乎无法“运行”该过程。

我一直在尝试寻找如何创建匿名 block 的示例,以便我可以将过程作为 SQL 文件运行,但尚未找到任何有效的方法。

有谁知道我如何从 SQL Developer 执行此过程?我使用的是版本2.1.1.64。

编辑1:

我要调用的过程具有以下签名:

user.package.procedure(
p_1 IN NUMBER,
p_2 IN NUMBER,
p_3 OUT VARCHAR2,
p_4 OUT VARCHAR2,
p_5 OUT VARCHAR2,
p_6 OUT NUMBER)

如果我这样写我的匿名 block :

DECLARE
out1 VARCHAR2(100);
out2 VARCHAR2(100);
out3 VARCHAR2(100);
out4 NUMBER(100);
BEGIN
EXECUTE user.package.procedure (33,89, :out1, :out2, :out3, :out4);
END;

我收到错误:

Bind Varialbe "out1" is NOT DECLCARED
anonymous block completed

我尝试初始化 out* 变量:

   out1 VARCHAR2(100) := '';

但得到同样的错误:

编辑2:

根据 Alex 的回答,我尝试删除参数前面的冒号并得到:

Error starting at line 1 in command:
DECLARE
out1 VARCHAR2(100);
out2 VARCHAR2(100);
out3 VARCHAR2(100);
out4 NUMBER(100);
BEGIN
EXECUTE user.package.procedure (33,89, out1, out2, out3, out4);
END;
Error report:
ORA-06550: line 13, column 17:
PLS-00103: Encountered the symbol "USER" when expecting one of the following:

:= . ( @ % ; immediate
The symbol ":=" was substituted for "USER" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

最佳答案

使用简单的参数类型(即不是引用游标等),您可以执行以下操作:

SET serveroutput on;
DECLARE
InParam1 number;
InParam2 number;
OutParam1 varchar2(100);
OutParam2 varchar2(100);
OutParam3 varchar2(100);
OutParam4 number;
BEGIN
/* Assign values to IN parameters */
InParam1 := 33;
InParam2 := 89;

/* Call procedure within package, identifying schema if necessary */
schema.package.procedure(InParam1, InParam2,
OutParam1, OutParam2, OutParam3, OutParam4);

/* Display OUT parameters */
dbms_output.put_line('OutParam1: ' || OutParam1);
dbms_output.put_line('OutParam2: ' || OutParam2);
dbms_output.put_line('OutParam3: ' || OutParam3);
dbms_output.put_line('OutParam4: ' || OutParam4);
END;
/

<小时/> 编辑以使用OP的规范,并使用另一种方法来利用 :var绑定(bind)变量:

var InParam1 number;
var InParam2 number;
var OutParam1 varchar2(100);
var OutParam2 varchar2(100);
var OutParam3 varchar2(100);
var OutParam4 number;

BEGIN
/* Assign values to IN parameters */
:InParam1 := 33;
:InParam2 := 89;

/* Call procedure within package, identifying schema if necessary */
schema.package.procedure(:InParam1, :InParam2,
:OutParam1, :OutParam2, :OutParam3, :OutParam4);
END;
/

-- Display OUT parameters
print :OutParam1;
print :OutParam2;
print :OutParam3;
print :OutParam4;

关于oracle - 在 SQL Developer 中运行存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3991721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com