ORA-01008 Not all variables bound (merge statement)

1.4k Views Asked by At

I would like to know what am I doing wrong with the following code. I'm trying to pass oledbparameters to a merge statement.

cmd.CommandText = "MERGE INTO MAPPINGS " +
                          "USING DUAL " +
                          "ON ( MAP_KEY = ? AND MAP_FROM = ? ) " +
                          "WHEN MATCHED THEN UPDATE SET MAP_TO = ? " +
                          "WHEN NOT MATCHED THEN INSERT (MAP_ID, MAP_KEY, MAP_FROM, MAP_TO) " +
                          "VALUES (seq_mappings.nextval,UPPER(?),LPAD(?,10,'0'),UPPER(?)) ";


            cmd.Parameters.Add("MAP_KEY1", OleDbType.VarChar);
            cmd.Parameters.Add("MAP_FROM1", OleDbType.VarChar);
            cmd.Parameters.Add("MAP_TO1", OleDbType.VarChar);
            cmd.Parameters.Add("MAP_KEY2", OleDbType.VarChar);
            cmd.Parameters.Add("MAP_FROM2", OleDbType.VarChar);
            cmd.Parameters.Add("MAP_TO2", OleDbType.VarChar);

            cmd.Parameters["MAP_KEY1"].Value = "AUART";
            cmd.Parameters["MAP_FROM1"].Value = cs_.CustomerNr;
            cmd.Parameters["MAP_TO1"].Value = cs_.AUART;
            cmd.Parameters["MAP_KEY2"].Value = "AUART";
            cmd.Parameters["MAP_FROM2"].Value = cs_.CustomerNr;
            cmd.Parameters["MAP_TO2"].Value = cs_.AUART;

            cmd.ExecuteNonQuery();

While debugging, I can see that all values passed to the parameters are not null, but then I get "ORA-01008 - Not all variables bound".

I think I'm parsing the parameters in a wrong way, but I don't know exactly how would be the correct way. I also know that oledbcommand does not support named parameters as well. So I tried to pass parameters following the correct order... but also with no success result.

Thank you very much, and sorry my English

0

There are 0 best solutions below