简体   繁体   English

从ac#Web服务调用PL / SQL存储过程的ORA 00936错误

[英]ORA 00936 error calling a PL/SQL stored procedure from a c# web service

I need some help calling a stored procedure designed to add sequence number to each row added by an Api POST method. 我需要一些帮助来调用存储过程,该存储过程旨在将序列号添加到Api POST方法添加的每一行中。

At the moment I get this error message: "ExceptionMessage": "ORA-20001: Get Next Sequence Failed.. -936 ORA-00936: missing expression\\nORA-06512: at \\"FOO_BAR.PROC_NEXT_SEQUENCE\\", line 19\\nORA-06512: at line 1" 目前,我收到此错误消息:“ ExceptionMessage”:“ ORA-20001:获取下一个序列失败。-936 ORA-00936:缺少表达式\\ nORA-06512:位于\\” FOO_BAR.PROC_NEXT_SEQUENCE \\“,行19 \\ nORA -06512:在第1行上”

I have tried numerous code changes suggested in questions on here and elsewhere but due to my lack of c#/Oracle specific knowledge I'm beginning to feel as if I'm going round in circles. 我已经尝试过在这里和其他地方提出的问题中建议的许多代码更改,但是由于我缺乏C#/ Oracle的专门知识,我开始感到仿佛在转转。

The procedure was tested successfully in SQL Developer. 该过程已在SQL Developer中成功测试。

I'm using VS2013 (update 5), Entity Framework v6.1.3, ODPnet via Nuget, Oracle 11.2 and Postman. 我正在使用VS2013(更新5),实体框架v6.1.3,通过Nuget的ODPnet,Oracle 11.2和Postman。

Stored Procedure 储存程序

PROCEDURE PROC_NEXT_SEQUENCE(
p_owner varchar2,
p_table varchar2,
p_seq_name varchar2,
p_seq_value out number)
AS
v_sql varchar2(4000) ; v_seq_value number :=0;
BEGIN 
if length(p_seq_name) >0 then v_sql := 'select '||p_owner||'.'||p_seq_name||'.nextval from dual';
else v_sql := 'select '||p_owner||'.'||p_table||'_seq.nextval from dual';
end if;
execute immediate v_sql into v_seq_value; p_seq_value := v_seq_value;
exception when others then raise_application_error(-20001, 'Get Next Sequence Failed.. '||sqlcode||' '||sqlerrm);
end;

c# C#

using System;
using System.Net;
using System.Data;
using System.Net.Http;
using System.Web.Http;
using System.Linq;
using System.Web.Http.Description;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;
using FooBarApi.Models;

    // POST: api/Location
    [HttpPost]
    [ResponseType(typeof(LOCATION))]
    [Route("", Name = "AddLocation")]
    public HttpResponseMessage AddLocation([FromBody]LOCATION Location)
    {
        // Access config file and connect to database
        OracleConnection conn = new OracleConnection("User Id=FOO_BAR; Password=foo_bar; Data Source=FOOBARTEST");

        // Setup call to stored procedure 
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "PROC_NEXT_SEQUENCE";
        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        // Assign parameters
        cmd.Parameters.Add("p_owner", OracleDbType.Varchar2);
        cmd.Parameters.Add("p_table", OracleDbType.Varchar2);
        cmd.Parameters.Add("p_seq_name", OracleDbType.Varchar2);
        cmd.Parameters.Add("p_seq_value", OracleDbType.Decimal).Direction = ParameterDirection.Output;

        // Execute stored procedure
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();

        db.LOCATIONS.Add(Location);
        db.SaveChanges();

        var response = Request.CreateResponse<LOCATION>(HttpStatusCode.Created, Location);

        string uri = Url.Link("GetLocations", new { LOSEQ = Location.LOSEQ });
        response.Headers.Location = new Uri(uri);
        return response;

    }

LocationModel.Context.cs LocationModel.Context.cs

namespace FooBarApi.Models
{
using System;
using System.Linq;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;

public partial class LocationEntities : DbContext
{
    public LocationEntities()
        : base("name=LocationEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<LOCATION> LOCATIONS { get; set; }

    public virtual Decimal PROC_NEXT_SEQUENCE(string p_OWNER, string p_TABLE, string p_SEQ_NAME, ObjectParameter p_SEQ_VALUE)
    {
        var p_OWNERParameter = p_OWNER != null ?
            new ObjectParameter("P_OWNER", p_OWNER) :
            new ObjectParameter("P_OWNER", typeof(string));

        var p_TABLEParameter = p_TABLE != null ?
            new ObjectParameter("P_TABLE", p_TABLE) :
            new ObjectParameter("P_TABLE", typeof(string));

        var p_SEQ_NAMEParameter = p_SEQ_NAME != null ?
            new ObjectParameter("P_SEQ_NAME", p_SEQ_NAME) :
            new ObjectParameter("P_SEQ_NAME", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("PROC_NEXT_SEQUENCE", p_OWNERParameter, p_TABLEParameter, p_SEQ_NAMEParameter, p_SEQ_VALUE);
    }
  }
}

Error Message 错误信息

"Message": "An error has occurred.",

"ExceptionMessage": "ORA-20001: Get Next Sequence Failed.. -936 ORA-00936: missing expression\nORA-06512: at \"FOO_BAR.PROC_NEXT_SEQUENCE\", line 19\nORA-06512: at line 1",

"ExceptionType": "Oracle.ManagedDataAccess.Client.OracleException",

"StackTrace": "

at OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId,     Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)

at OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean bFirstIterationDone)

at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, Boolean isFromEF)

at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()

at FooBarApi.Controllers.LocationController.PostLocation(LOCATION Location) in     c:\\mvcApps\\FooBarApi\\FooBarApi\\Controllers\\LocationController.cs:line 71

at lambda_method(Closure , Object , Object[] )

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}

Update 更新资料

I've updated my code to reflect the errors found by Gary Myers and Aisha. 我已经更新了代码,以反映Gary Myers和Aisha发现的错误。 I've also added the Error Message/Stack Trace in case this helps. 如果有帮助,我还添加了错误消息/堆栈跟踪。

Thank you in advance. 先感谢您。

打字错误提供者/所有者:

cmd.Parameters.Add("p_onwer", OracleDbType.Varchar2);

try this SP, given a space after SELECT statement: 尝试此SP,在SELECT语句后给定空格:

PROCEDURE PROC_NEXT_SEQUENCE(
p_owner varchar2,
p_table varchar2,
p_seq_name varchar2,
p_seq_value out number)
AS
v_sql varchar2(4000) ; v_seq_value number :=0;
BEGIN 
if length(p_seq_name) >0 then v_sql := 'select '||p_owner||'.'||p_seq_name||'.nextval from dual';
else v_sql := 'select '||p_owner||'.'||p_table||'_seq.nextval from dual';
end if;
execute immediate v_sql into v_seq_value; p_seq_value := v_seq_value;
exception when others then raise_application_error(-20001, 'Get Next Sequence Failed.. '||sqlcode||' '||sqlerrm);
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ORA-06502:PL / SQL:数字或值错误从C#Web服务调用存储过程 - ORA-06502: PL/SQL: numeric or value error calling a stored procedure from c# web service 在 Web 应用程序中从 C# 代码调用存储过程返回 PL/SQL:数字或值错误:字符串缓冲区太小 - Calling stored procedure from C# code in web application returns PL/SQL: numeric or value error: character string buffer too small 错误ora 06576,调用Oracle存储过程C# - Error ora 06576 , Calling Oracle Stored Procedure C# 从C#代码调用SQL Server存储过程时出错 - Error calling SQL Server stored procedure from C# code 从C#调用存储过程时出错 - Error with calling stored procedure from C# 通过C#使用linq服务调用SQL Server存储过程 - Calling a SQL Server stored procedure with linq service through c# 从C#代码调用存储过程时,出现SQL错误“过程或函数需要参数,但未提供” - Sql error “Procedure or function expects parameter , which was not supplied” when calling a stored procedure from c# code 从C#应用程序动态调用SQL Server存储过程 - Dynamically calling a SQL Server stored procedure from a C# application 从 C# 调用 oracle 存储过程时出现 ORA-06550 异常 - ORA-06550 exception while calling oracle stored procedure from C# 从C#调用我的存储过程时出错 - Getting an error calling my stored procedure from c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM