如何从 WebMatrix 调用 Oracle 存储过程?

发布于 2024-11-26 14:15:29 字数 789 浏览 1 评论 0原文

我正在尝试使用 Microsoft WebMatrix 中的 WebMatrix.Data 执行 Oracle 存储过程。我可以使用正常的 select 语句很好地获取数据...但我一生都无法弄清楚如何执行 Oracle 过程。据我所知,它不像 T-SQL 过程那样执行。请帮忙!

我正在尝试恢复单个值。我只是想证明我可以使用 webmatrix.data 访问 oracle 存储过程。这是一个查询,所以我不确定 db.Execute 是否有效,因为它适用于非查询。

这是代码:

 CREATE OR REPLACE PROCEDURE COUNT_JOB_HISTORY
 (
   reccount OUT NUMBER
 )
 IS
   BEGIN
     SELECT COUNT(*) INTO reccount
     FROM JOB_HISTORY;
   END COUNT_JOB_HISTORY;

这是 .Net 代码

    public static dynamic GetJobHistoryCount()
    {
        var db = Database.OpenConnectionString(connectionString, providerName);

        var jobs = db.QueryValue("exec COUNT_JOB_HISTORY(:0)", "count");

        return jobs;
    }

它会爆炸为 ORA-00900:无效的 SQL 语句

谢谢!

I am trying to execute an oracle stored procedure using WebMatrix.Data from Microsoft's WebMatrix. I can get data just fine with normal select statements...but I can't for the life of me figure out how to execute an oracle proc. It's not executed like a T-SQL proc I know that. Please help!

I'm trying to get a single value back. I'm just trying to prove that I can access an oracle stored proc with webmatrix.data. It is a query so I'm not sure db.Execute would work since that is for non-queries.

here's the code:

 CREATE OR REPLACE PROCEDURE COUNT_JOB_HISTORY
 (
   reccount OUT NUMBER
 )
 IS
   BEGIN
     SELECT COUNT(*) INTO reccount
     FROM JOB_HISTORY;
   END COUNT_JOB_HISTORY;

Here's the .Net code

    public static dynamic GetJobHistoryCount()
    {
        var db = Database.OpenConnectionString(connectionString, providerName);

        var jobs = db.QueryValue("exec COUNT_JOB_HISTORY(:0)", "count");

        return jobs;
    }

It blows up as an ORA-00900 : invalid SQL statement

Thanks!

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

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

发布评论

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

评论(1

灵芸 2024-12-03 14:15:29

您需要使用db.Execute()(请参阅http://msdn.microsoft.com/en-us/library/webmatrix.data.database.execute%28v=vs.99%29.aspx)...

关于过程本身以及处理参数/结果很难说,因为您没有提供足够的信息,例如

过程返回什么?一个值?一排?光标?

编辑-在OP显示存储过程之后:

每个存储过程都是“非查询”-WebMatrix不知道存储过程内部发生的事情......
我从未使用过 WebMatrix...所以这只是一个猜测:

int reccount = 0;
db.Execute ("COUNT_JOB_HISTORY", reccount);

或者也许

db.Execute ("COUNT_JOB_HISTORY", ref reccount); 

编辑2 - 另一次尝试:

db.Execute ("BEGIN COUNT_JOB_HISTORY(:0); END;", reccount);

you need to use db.Execute() (see http://msdn.microsoft.com/en-us/library/webmatrix.data.database.execute%28v=vs.99%29.aspx)...

Regardings the procedure itself and dealing with params/result it is hard to tell because you did not provide enough information like

What exactly does the procedure return ? one value ? one row ? a cursor ?

EDIT- after the OP showed the Stored Procedure:

Every Stored Procedure is a "Non-Query" - WebMatrix does not know anything about what happens inside the Stored Procedure...
I never used WebMatrix... so this is only a guess:

int reccount = 0;
db.Execute ("COUNT_JOB_HISTORY", reccount);

or perhaps

db.Execute ("COUNT_JOB_HISTORY", ref reccount); 

EDIT 2 - another try:

db.Execute ("BEGIN COUNT_JOB_HISTORY(:0); END;", reccount);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文