0

I have a stored procedure that works and has been working for months for inserting data.

Here's the "short" version:

procedure saveApplication(  in_confirmation_number  varchar2 := null                           
                            ,in_nonstandard_address varchar2 := null      
                            ,in_absentee_type varchar2 := null) AS
  BEGIN
    insert into vr_application (
            confirmation_number
            ,nonstandard_address
            ,absentee_type )
    values ( in_confirmation_number
            ,in_nonstandard_address
            ,in_absentee_type 
            );
END;

I'm working in bulk so I stuff the data in as arrays after pulling the value from a datatable. Again, below is the "shortened" version.

private static void loadFiles(DataTable dt, string connString, ErrorLogger log)
    {

        OracleConnection orclconn = null;
        OracleCommand cmd = null;

        using (orclconn = new OracleConnection(connString))
        {
            orclconn.Open();
            using (cmd = BuildCommand(dt))
            {
                cmd.Connection = orclconn;
                cmd.ExecuteNonQuery();
            }
        }

    }

 private static OracleCommand BuildCommand(DataTable dt)
    {
        OracleCommand cmd = new OracleCommand();
        cmd.CommandText = "Applications.saveApplication";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.ArrayBindCount = dt.Rows.Count;
        cmd.BindByName = true;

        string[] CONFIRMATION_NUMBER = dt
           .AsEnumerable()
           .Select(row => row.Field<string>("CONFIRMATION_NUMBER"))
           .ToArray();
        OracleParameter in_confirmation_number = new OracleParameter();
        in_confirmation_number.OracleDbType = OracleDbType.Varchar2;
        in_confirmation_number.Value = CONFIRMATION_NUMBER;
        in_confirmation_number.ParameterName = "in_confirmation_number";
        cmd.Parameters.Add(in_confirmation_number);

         string[] ABSENTEE_TYPE = dt
            .AsEnumerable()
            .Select(row => row.Field<string>("ABSENTEE_TYPE"))
            .ToArray();
        OracleParameter in_absentee_type = new OracleParameter();
        in_absentee_type.OracleDbType = OracleDbType.Varchar2;
        in_absentee_type.Value = ABSENTEE_TYPE;
        in_absentee_type.ParameterName = "in_absentee_type";
        cmd.Parameters.Add(in_absentee_type);

        string[] NONSTANDARD_ADDRESS = dt
         .AsEnumerable()
         .Select(row => row.Field<string>("NONSTANDARD_ADDRESS"))
         .ToArray();
        OracleParameter in_nonstandard_address = new OracleParameter();
        in_absentee_type.OracleDbType = OracleDbType.Varchar2;
        in_absentee_type.Value = NONSTANDARD_ADDRESS;
        in_absentee_type.ParameterName = "in_nonstandard_address";
        cmd.Parameters.Add(in_nonstandard_address);

        return cmd;
}

Scenario 1: nonstandard_address code is commented out. Everything works.

Scenario 2: nonstandard_address code is not commented out. But instead of passing values into the original datatable, I hardcode the value "null". Everything works. This is where it has been for months.

Scenario 3: the datatable for nonstandard address has a single row which has a value in nonstandard address. All other rows contain null for this column. I get an Oracle.DataAccess.Client.OracleException, #ORA-06550, with the message "Encountered the symbol ">" when expecting one of the following...."

To attempt to identify the problem, I simply looped through the values in the array. I get the same error on the last loop iteration, which is always one more than the number of records in the data table (100). But if I loop without attempting to create an Oracle Parameter for nonstandard, I get no error and only 100 loop iterations.

If I do Scenario 2 and successfully fill the table with everything except nonstandard_address, I can then run the following in Oracle, and successfully update the table.

update vr_application a
set nonstandard_address = (select nonstandard_address from unprocessed_apps b where b.confirmation_number = a.confirmation_number)
where exists (select 1 from unprocessed_apps where confirmation_number = a.confirmation_number)

Can anyone see a mistake here? Anyone seen this before? I'm baffled.

4

1 回答 1

0

嗯,这是那些“duh”时刻之一,也是拥有可以成为额外眼睛的同事的一个很好的论据。

查看我的代码 - 我将地址输入到缺席字段中。这就是我所拥有的:

    string[] NONSTANDARD_ADDRESS = dt
     .AsEnumerable()
     .Select(row => row.Field<string>("NONSTANDARD_ADDRESS"))
     .ToArray();
    OracleParameter in_nonstandard_address = new OracleParameter();
    **in_absentee_type**.OracleDbType = OracleDbType.Varchar2;
    **in_absentee_type**.Value = NONSTANDARD_ADDRESS;
    **in_absentee_type**.ParameterName = "in_nonstandard_address";
    cmd.Parameters.Add(in_nonstandard_address);

这是我应该拥有的:

       string[] NONSTANDARD_ADDRESS = dt
           .AsEnumerable()
           .Select(row => row.Field<string>("NONSTANDARD_ADDRESS"))
           .ToArray();
        OracleParameter in_nonstandard_address = new OracleParameter();
        **in_nonstandard_address**.OracleDbType = OracleDbType.Varchar2;
        **in_nonstandard_address**.Value = NONSTANDARD_ADDRESS;
        **in_nonstandard_address**.ParameterName = "in_nonstandard_address";
        cmd.Parameters.Add(in_nonstandard_address);

像上面那样盯着72个阵列后,我的眼睛完全错过了它。感谢 Bob Jarvis 提出的一些让我突然想到语法问题的建议。

于 2012-07-21T15:55:11.437 回答