如何执行oracle存储过程?

发布于 2024-08-13 14:01:51 字数 320 浏览 3 评论 0原文

我使用的是oracle 10g Express版。它为数据库开发人员提供了一个很好的用户界面。但我在执行存储过程时遇到一些问题。

过程:

create or replace procedure temp_proc is
begin
  DBMS_OUTPUT.PUT_LINE('Test');
end

创建成功。但是当我执行:

execute temp_proc;

时,它显示ORA-00900:无效的SQL语句

所以这里需要帮助

I am using oracle 10g express edition. It has a nice ui for db developers. But i am facing some problems executing stored procedures.

Procedure:

create or replace procedure temp_proc is
begin
  DBMS_OUTPUT.PUT_LINE('Test');
end

it is created successfully. But when i execute:

execute temp_proc;

it shows ORA-00900: invalid SQL statement

So help needed here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

各空 2024-08-20 14:01:52

Execute 是 sql*plus 语法.. 尝试将您的调用包装在 begin .. end 中,如下所示:(

begin 
    temp_proc;
end;

虽然 Jeffrey 说这在 APEX 中不起作用 .. 但您正在尝试让它运行在 SQLDeveloper 中..尝试那里的“运行”菜单。)

Execute is sql*plus syntax .. try wrapping your call in begin .. end like this:

begin 
    temp_proc;
end;

(Although Jeffrey says this doesn't work in APEX .. but you're trying to get this to run in SQLDeveloper .. try the 'Run' menu there.)

简单 2024-08-20 14:01:52

“is”和“as”都是有效的语法。默认情况下,输出禁用。尝试一个也支持输出的过程...

create or replace procedure temp_proc is
begin
  DBMS_OUTPUT.ENABLE(1000000);
  DBMS_OUTPUT.PUT_LINE('Test');
end;

...并在 PLSQL 块中调用它...

begin
  temp_proc;
end;

...因为 SQL 是非过程的。

Both 'is' and 'as' are valid syntax. Output is disabled by default. Try a procedure that also enables output...

create or replace procedure temp_proc is
begin
  DBMS_OUTPUT.ENABLE(1000000);
  DBMS_OUTPUT.PUT_LINE('Test');
end;

...and call it in a PLSQL block...

begin
  temp_proc;
end;

...as SQL is non-procedural.

还在原地等你 2024-08-20 14:01:52

Oracle 10g Express Edition 附带内置的 Oracle Application Express (Apex)。您在其 SQL 命令窗口中运行它,该窗口不支持 SQL*Plus 语法。

这并不重要,因为(正如您所发现的)BEGIN...END 语法在 Apex 中确实有效。

Oracle 10g Express Edition ships with Oracle Application Express (Apex) built-in. You're running this in its SQL Commands window, which doesn't support SQL*Plus syntax.

That doesn't matter, because (as you have discovered) the BEGIN...END syntax does work in Apex.

指尖上得阳光 2024-08-20 14:01:52

在使用 12c 的 Oracle SQL Developer (GUI) 中,也不要忘记启用 DMBS Output 窗口(单击 View => Dbms Output >,然后单击“+”符号,并选择您的连接),默认情况下该窗口未启用。

DBMS 输出窗口
DBMS 输出windowenabled

以下语法将输出到该窗口:

begin
  temp_proc
end;

In Oracle SQL Developer (GUI), using 12c, also don't forget to enable the DMBS Output window (click View => Dbms Output, then click "+" sign, and select your connection), by default the window is not enabled.

DBMS Output window
DBMS output window enabled

The following syntax will then output to this window:

begin
  temp_proc
end;
睫毛上残留的泪 2024-08-20 14:01:52

我使用 oracle 12,它告诉我,如果您需要调用该过程,请使用 call 关键字。
在你的情况下应该是:

begin
  call temp_proc;
end;

I use oracle 12 and it tell me that if you need to invoke the procedure then use call keyword.
In your case it should be:

begin
  call temp_proc;
end;
铁憨憨 2024-08-20 14:01:52

您可以在命令行窗口上简单地执行以下操作:

Connected to Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 
Connected as XXX@YYY


SQL> call temp_proc();

或者:

SQL> execute temp_proc();

You can do simply the following on the Command Window:

Connected to Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 
Connected as XXX@YYY


SQL> call temp_proc();

Or:

SQL> execute temp_proc();
旧伤还要旧人安 2024-08-20 14:01:52

您是否尝试过像这样纠正语法?:

create or replace procedure temp_proc AS
begin
  DBMS_OUTPUT.PUT_LINE('Test');
end;

Have you tried to correct the syntax like this?:

create or replace procedure temp_proc AS
begin
  DBMS_OUTPUT.PUT_LINE('Test');
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文