如何使用 Oracle SQL Developer 运行存储过程?
* EDIT6:* 这就是最终为我工作的内容(来自已接受的答案):
var ret1 number
var tran_cnt number
var msg_cnt number
var rc refcursor
exec :tran_cnt := 0
exec :msg_cnt := 123
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => :rc)
print :tran_cnt
print :msg_cnt
print :rc
SQL Developer 使这变得超级困难/不可能?。我不关心该实用程序是否基于命令行;我只是希望能够快速运行并查看它。如果它也能捕获错误那就太好了。如果能够逐渐(交互式)登录,以及一次指定所有内容(类似于典型的 ftp / sftp 基于 cmd 的客户端的工作方式),那就太好了。
我的平台是Windows Server 2008 + Cygwin。
编辑:也许您知道如何使用 Python 编写脚本?
编辑2:在MSFT SQL服务器中,我可以简单地输入:
get_user 1;
然后突出显示它并按F5,然后我得到:
login name
NULL Somename
打印到输出窗口。 Oracle SQL 开发人员对此根本没有帮助。我不知道如何传递 1,我不知道如何查看返回的实际行/记录。
编辑3:当我仅输入var rc refcursor;
并选择它并运行它时,我收到此错误(GUI):
An error was encountered performing the requested operation:
ORA-00900: invalid SQL statement
00900.00000 - "invalid SQL statement"
* Cause:
* Action:
Vendor code 900Error at Line: 2
< em>EDIT4:
我正在尝试运行一个过程,其定义如下所示:
create or replace procedure get_account
(
Vret_val out number,
Vtran_count in out number,
Vmessage_count in out number,
Vaccount_id IN NUMBER
, rc1 in out sys_refcursor
)as
begin
...
我收到错误:
Error starting at line 2 in command:
exec :rc := get_account(1)
Error report:
ORA-06550: line 1, column 24:
PLS-00306: wrong number or types of arguments in call to 'GET_ACCOUNT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
rc
------
我非常接近...请帮助。
* 编辑 5:*
我正在运行的脚本(功能相同),错误始终相同:
var ret1 number
var tran_cnt number
var msg_cnt number
var rc refcursor
exec :tran_cnt := 0
exec :msg_cnt := 123
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
脚本输出(在 F5 上)(可能是来自多次运行的多条消息。):
Error report:
ORA-06550: line 1, column 134:
PLS-00201: identifier 'RC' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
anonymous block completed
anonymous block completed
Error starting at line 7 in command:
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
Error report:
ORA-06550: line 1, column 134:
PLS-00201: identifier 'RC' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
anonymous block completed
anonymous block completed
Error starting at line 7 in command:
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
Error report:
ORA-06550: line 1, column 134:
PLS-00201: identifier 'RC' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
为什么会这样比如说第 1 行第 134 列?没有一条线可以延伸那么远...
* EDIT6: * This is what ended up working for me (from accepted answer):
var ret1 number
var tran_cnt number
var msg_cnt number
var rc refcursor
exec :tran_cnt := 0
exec :msg_cnt := 123
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => :rc)
print :tran_cnt
print :msg_cnt
print :rc
The SQL Developer makes this super-hard / impossible?. I do not care if the utility is command-line-based; I just want to be able to run and view it quickly. It would be nice if it captured errors well as well. it would be nice to be able to log in gradually(interactively), as well as specifying everything at once (similar to how a typical ftp / sftp cmd-based client works).
My platform is Windows Server 2008 + Cygwin.
EDIT: Perhaps you would know how to script this using Python?
EDIT 2: In MSFT SQL server I can simply type this:
get_user 1;
then highlight it and hit F5, and I get:
login name
NULL Somename
printed to the output window. The Oracle SQL developer does not help with this at all. I am not sure how to pass in a 1, I am not sure how to see the actual rows/records that come back.
EDIT3: When I type just var rc refcursor;
and select it and run it, I get this error (GUI):
An error was encountered performing the requested operation:
ORA-00900: invalid SQL statement
00900.00000 - "invalid SQL statement"
* Cause:
* Action:
Vendor code 900Error at Line: 2
EDIT4:
I am trying to run a procedure the definition of which starts like this:
create or replace procedure get_account
(
Vret_val out number,
Vtran_count in out number,
Vmessage_count in out number,
Vaccount_id IN NUMBER
, rc1 in out sys_refcursor
)as
begin
...
I get an error:
Error starting at line 2 in command:
exec :rc := get_account(1)
Error report:
ORA-06550: line 1, column 24:
PLS-00306: wrong number or types of arguments in call to 'GET_ACCOUNT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
rc
------
I am so close ... please help.
* EDIT 5: *
Script that I am running (functionally the same), the error was always the same:
var ret1 number
var tran_cnt number
var msg_cnt number
var rc refcursor
exec :tran_cnt := 0
exec :msg_cnt := 123
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
Script Output (on F5) (Could be several messages from several runs.):
Error report:
ORA-06550: line 1, column 134:
PLS-00201: identifier 'RC' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
anonymous block completed
anonymous block completed
Error starting at line 7 in command:
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
Error report:
ORA-06550: line 1, column 134:
PLS-00201: identifier 'RC' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
anonymous block completed
anonymous block completed
Error starting at line 7 in command:
exec get_account(Vret_val => :ret1, Vtran_count => :tran_cnt, Vmessage_count => :msg_cnt, Vaccount_id => 1, rc1 => rc)
Error report:
ORA-06550: line 1, column 134:
PLS-00201: identifier 'RC' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Why does it say line 1, column 134? No line stretched that far ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不仅有一种方法可以做到这一点,而且有不止一种方法可以做到这一点(我承认这不是很 Pythonic,但 SQL*Developer 是用 Java 编写的)。
我有一个带有此签名的过程:
get_maxsal_by_dept(dno number, maxsal out number)
。我在 SQL*Developer 对象导航器中突出显示它,调用右键单击菜单并选择运行。 (我可以使用 ctrl+F11。)这会生成一个带有测试工具的弹出窗口。 (注意:如果存储过程位于包中,则需要右键单击该包,而不是包含过程名称的包下面的图标;您将然后当测试工具出现时,从包的“目标”列表中选择存储过程。)在此示例中,测试工具将显示以下内容:
我将变量 DNO 设置为 50,然后按“确定”。在“运行 - 日志”窗格(右下角,除非您关闭/移动/隐藏它)中,我可以看到以下输出:
公平地说,运行程序对于返回引用游标,如下所示:
get_emps_by_dept (dno number) return sys_refcursor
。然而,至少它提供了保存对文件的任何更改的机会,因此我们可以保留调整工具的投资...
来自同一位置的输出:
或者我们可以在 SQL 中使用旧的 SQLPLus 命令开发人员工作表:
在这种情况下,输出将显示在脚本输出窗格中(默认位置是结果选项卡右侧的选项卡)。
IDE 的最早版本对 SQL*Plus 的支持并不多。不过,从 1.2.1 开始,所有上述命令都得到支持。有关详细信息,请参阅在线文档中的矩阵 。
工作表解释 SQLPlus 命令的方式存在一个功能或错误。它假定 SQLPlus 命令是脚本的一部分。因此,如果我们输入一行对于 SQL*Plus,说
var rc refcursor
并单击Execute Statement
(或 F9),工作表会抛出 ORA-900 因为这是不是可执行语句,即它不是 SQL ,我们需要做的是单击Run Script
(或 F5 ),即使对于单行 SQL*Plus 也是如此。 。您的程序是一个带有五个强制参数签名的过程。您收到错误是因为您将其作为函数调用,并且仅使用一个参数:
您需要的是如下所示的内容。为了清楚起见,我使用了命名符号。
也就是说,每个 OUT 或 IN OUT 参数都需要一个变量。 IN 参数可以作为文字传递。前两个 EXEC 语句将值分配给几个 IN OUT 参数。第三个 EXEC 调用该过程。过程不返回值(与函数不同),因此我们不使用赋值语法。最后,该脚本显示映射到 OUT 参数的几个变量的值。
Not only is there a way to do this, there is more than one way to do this (which I concede is not very Pythonic, but then SQL*Developer is written in Java ).
I have a procedure with this signature:
get_maxsal_by_dept( dno number, maxsal out number)
.I highlight it in the SQL*Developer Object Navigator, invoke the right-click menu and chose Run. (I could use ctrl+F11.) This spawns a pop-up window with a test harness. (Note: If the stored procedure lives in a package, you'll need to right-click the package, not the icon below the package containing the procedure's name; you will then select the sproc from the package's "Target" list when the test harness appears.) In this example, the test harness will display the following:
I set the variable DNO to 50 and press okay. In the Running - Log pane (bottom right-hand corner unless you've closed/moved/hidden it) I can see the following output:
To be fair the runner is less friendly for functions which return a Ref Cursor, like this one:
get_emps_by_dept (dno number) return sys_refcursor
.However, at least it offers the chance to save any changes to file, so we can retain our investment in tweaking the harness...
The output from the same location:
Alternatively we can use the old SQLPLus commands in the SQLDeveloper worksheet:
In that case the output appears in Script Output pane (default location is the tab to the right of the Results tab).
The very earliest versions of the IDE did not support much in the way of SQL*Plus. However, all of the above commands have been supported since 1.2.1. Refer to the matrix in the online documentation for more info.
There is a feature - or a bug - in the way the worksheet interprets SQLPlus commands. It presumes SQLPlus commands are part of a script. So, if we enter a line of SQL*Plus, say
var rc refcursor
and clickExecute Statement
(or F9 ) the worksheet hurls ORA-900 because that is not an executable statement i.e. it's not SQL . What we need to do is clickRun Script
(or F5 ), even for a single line of SQL*Plus.You program is a procedure with a signature of five mandatory parameters. You are getting an error because you are calling it as a function, and with just the one parameter:
What you need is something like the following. I have used the named notation for clarity.
That is, you need a variable for each OUT or IN OUT parameter. IN parameters can be passed as literals. The first two EXEC statements assign values to a couple of the IN OUT parameters. The third EXEC calls the procedure. Procedures don't return a value (unlike functions) so we don't use an assignment syntax. Lastly this script displays the value of a couple of the variables mapped to OUT parameters.
存储过程不返回记录。它们可能有一个游标作为输出参数,它是一个指向 select 语句的指针。但它需要额外的操作才能真正从该游标中取回行。
在 SQL Developer 中,您可以执行返回引用游标的过程,如下所示。
之后,如果执行以下命令,它将显示游标的结果:
Stored procedures do not return records. They may have a cursor as an output parameter, which is a pointer to a select statement. But it requires additional action to actually bring back rows from that cursor.
In SQL Developer, you can execute a procedure that returns a ref cursor as follows
After that, if you execute the following, it will show the results from the cursor:
我的推荐是TORA
My recommendation is TORA
您听说过“SQuirreL SQL 客户端”吗?
http://squirrel-sql.sourceforge.net/
Have you heard of "SQuirreL SQL Client"?
http://squirrel-sql.sourceforge.net/
有两种可能性,均来自 Quest Software、TOAD 和 Quest Software。 SQL Navigator:
这是 TOAD 免费软件下载: http:// www.toadworld.com/Downloads/FreewareandTrials/ToadforOracleFreeware/tabid/558/Default.aspx
和 SQL Navigator(试用版):http://www.quest.com/sql-navigator/software-downloads.aspx
There are two possibilities, both from Quest Software, TOAD & SQL Navigator:
Here is the TOAD Freeware download: http://www.toadworld.com/Downloads/FreewareandTrials/ToadforOracleFreeware/tabid/558/Default.aspx
And the SQL Navigator (trial version): http://www.quest.com/sql-navigator/software-downloads.aspx