简体   繁体   English

添加参数时,oracle值不在预期范围内

[英]Value does not fall within the expected range, when adding parameters, oracle

When adding parameters to Oracle Stored Procedure in Unit Testing, i get error on adding RowId. 在单元测试中向Oracle存储过程添加参数时,添加RowId时出现错误。 I tried adding ToString() but then another error - "ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'CultureInsert'". 我尝试添加ToString(),但随后出现另一个错误-“ ORA-06550:第1行,第7列:PLS-00306:调用'CultureInsert'时参数或参数类型错误”。 I am not sure i am getting to the procedure. 我不确定我要进行程序了。 The error is in the DoInsert function. 该错误在DoInsert函数中。

[TestMethod]
public void InsertTest()
{
    var culture = new Culture();
    var insertData = new CultureData();
    insertData.Name = "insertedName5";
    insertData.Code = "en-HK";
    insertData.Description = "InsertDescription";

    var data = culture.Insert(insertData);
}

________________________________________________________

public CultureData Insert(CultureData data)
{
    try
    {
        string oradb = "Data Source=(DESCRIPTION =" + "(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))" + "(CONNECT_DATA =" + "(SERVER = DEDICATED)" + "(SERVICE_NAME = XE)));" + "User Id= ****;Password=****;";

        OracleConnection conn = new OracleConnection(oradb); // C#
        conn.Open();

        using (var cmm = new OracleCommand("CultureInsert",conn))
        {

            cmm.CommandType = CommandType.StoredProcedure;

            if (data.Name != null && data.Code != null && data.Description != null)
            {
                DoInsert(cmm, data);
            }
            else
            {
                throw new System.Exception(string.Format("Inserting record failed! Name, Code and Description must be entered!"));
            }

        }
        conn.Dispose();

    }
    catch (SqlException exception)
    {
        SqlExceptionHandler.Throw(exception);
    }

    return data;
}

This is the stored procedure: 这是存储过程:

create or replace 
PROCEDURE           CultureInsert(
  v_Id              IN OUT NUMBER,
    v_Code            IN NVARCHAR2,
    v_Name            IN NVARCHAR2,
    v_Description     IN NVARCHAR2,
    v_Disabled        IN NUMBER DEFAULT 0,
    v_RowId           IN RAW,
    v_AuditUser       IN NVARCHAR2,
    v_AuditSessionId  IN RAW)
   as
   v_TransactionName  CHAR(32);
   v_TransCount  NUMBER(10,0);
   v_DisplayField  NVARCHAR2(24);
   SWV_TRANCOUNT NUMBER(10,0);
BEGIN

   v_TransactionName := 'CultureInsert';

   v_TransCount := 1  /*NOT SUPPORTED @@TRANCOUNT*/;

   IF (v_TransCount = 0) then
      SAVEPOINT v_TransactionName;
      SWV_TRANCOUNT := 0;
      SWV_TRANCOUNT := SWV_TRANCOUNT+1;
   ELSE
      NULL;
      -- SAVE TRANSACTION @TransactionName
end if;

   BEGIN 

INSERT INTO Core.Culture(Code,
            Name,
            Description,
            Disabled,
            RowId_)
        VALUES(v_Code,
            v_Name,
            v_Description,
            v_Disabled,
            v_RowId);

      select Core.Culture_Id.CURRVAL into v_Id from dual;
      Core.CultureAuditInsert(v_Id,v_AuditUser,'I',v_AuditSessionId);
      Core.CultureFetch(v_Id,v_AuditUser,v_AuditSessionId);
      v_DisplayField := Core.GetCultureDisplayFieldById(v_Id);
      Core.RecentWorkSave('Core','Culture',v_Id,v_DisplayField,v_AuditUser);
      IF v_TransCount = 0 then
         COMMIT;
         SWV_TRANCOUNT := SWV_TRANCOUNT -1;
      end if;
      EXCEPTION WHEN OTHERS THEN
         IF SWV_TRANCOUNT > 0 then
            ROLLBACK;
            SWV_TRANCOUNT := 0;
         end if;
         --THROW;
   END;

END;

here is where i get an error: 这是我得到错误的地方:

internal static CultureData DoInsert(OracleCommand cmm, CultureData data)
{
    cmm.Parameters.Add(CultureData.IdProperty, data.Id);
    cmm.Parameters.Add(CultureData.CodeProperty, data.Code);
    cmm.Parameters.Add(CultureData.NameProperty, data.Name);
    cmm.Parameters.Add(CultureData.DescriptionProperty, data.Description);
    cmm.Parameters.Add(CultureData.DisabledProperty, data.Disabled);
    cmm.Parameters.Add(CultureData.RowIdProperty, data.RowId); //here is the problem
    cmm.Parameters.Add(CultureData.AuditUserProperty, Csla.ApplicationContext.User.Identity.Name);
    cmm.Parameters.Add(CultureData.AuditSessionIdProperty, Csla.ApplicationContext.User.Identity.GetSessionId());
    using (OracleDataReader reader = cmm.ExecuteReader())
        return DoFetch(DataReaderHelper.GetReader(reader));
}

The ROWID pseudocolumn is automatically generated. ROWID伪列是自动生成的。 From the docs : 文档

You cannot insert, update, or delete a value of the ROWID pseudocolumn. 您不能插入,更新或删除ROWID伪列的值。

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

相关问题 值不在Oracle的预期范围内 - value does not fall within the expected range exception for Oracle 值不在预期范围内,孤立存储 - Value does not fall within the expected range, IsolatedStorage 值不在预期范围内 - value does not fall within expected range 值不在预期范围内 - Value does not fall within the expected range WinRT - 值不在预期范围内 - WinRT - Value does not fall within the expected range ArgumentException:值不在预期范围内 - ArgumentException: Value does not fall within the expected range DeviceConnectionChangeTrigger-值不在预期范围内 - DeviceConnectionChangeTrigger - Value does not fall within the expected range BackgroundTaskRegistration-值不在预期范围内 - BackgroundTaskRegistration - Value does not fall within the expected range Oracle.DataAccess(ODP.NET)数组绑定“值不在预期范围内” - Oracle.DataAccess (ODP.NET) Array Binding “Value does not fall within the expected range” Web.GetFileByServerRelativeUrl抛出“值不在预期范围内” - Web.GetFileByServerRelativeUrl throws “Value does not fall within expected range”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM