在 Excel VBA 中执行 PL/SQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21232351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:27:40  来源:igfitidea点击:

Execute PL/SQL insde Excel VBA

oraclevbaplsql

提问by Vinod Chelladurai

am having a PL/SQL procedure like below:

我有一个 PL/SQL 程序,如下所示:

create or replace procedure forecast_real_dates_procedure
IS
BEGIN
DELETE FROM FORECAST_REAL_DATES_TABLE;
insert into FORECAST_REAL_DATES_TABLE select * from FORECAST_REAL_DATES_VIEW;
END;
/

I want to execute this procedure inside a excel vba (i.e.), run the statement execute forecast_real_dates_procedure inside the vba. I have already done with connecting to oracle from vba and all those stuffs. But, just confused with the command to do this. Can anyone please help me on this.

我想在excel vba(即)中执行这个程序,在vba中运行语句execute predict_real_dates_procedure。我已经完成了从 vba 和所有这些东西连接到 oracle 的工作。但是,只是与执行此操作的命令混淆。任何人都可以帮我解决这个问题。

thanks

谢谢

回答by Wernfried Domscheit

Try this one (not tested):

试试这个(未测试):

Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command

con.provider = "OraOLEDB.Oracle"
con.CursorLocation = adUseClient
con.Open "PLSQLRSet=0;Data Source=<YOUR_DATABASE>" , "<USER>", "<Password>"
Set cmd.ActiveConnection = con

cmd.CommandType = adCmdStoredProc
cmd.CommandText = "forecast_real_dates_procedure"
cmd.Execute
con.Close

You have to add the reference to you VBA Macro in: Tools -> References -> Enable "Microsoft ActiveX Data Objects 2.? Library"

您必须在以下位置添加对 VBA 宏的引用:工具 -> 引用 -> 启用“Microsoft ActiveX Data Objects 2.? Library”

回答by Vinod Chelladurai

I found the solution for this.

我找到了解决方案。

Just do the following code

只需执行以下代码

Set cmd = New ADODB.Command
With cmd
 .ActiveConnection = cn
 .CommandType = adCmdStoredProc
 .CommandText = "forecast_real_dates_procedure"
 .Execute , , adExecuteNoRecords
End With