0

Currently only [A] has been tested. Is [B] possible?

[A]:

SELECT code, country, currency_code FROM countries
WHERE currency_code = ? AND code = ?

[B]:

SELECT code, country, currency_code FROM countries
WHERE currency_code = :currency_code AND code = :code

Oracle has the following method.

  using var command = new OracleCommand(query, connection);

  command.BindByName = true;

( Binding query parameters by name with ODP.NET )

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • Either way should work. The major difference is that version [B] can't pass null values. (To add null value capability, you should do something like :currency_code :indicator.) – jarlh Dec 13 '21 at 19:40
  • @jarlh Thank you for editing my article beautifully. As you said, [B] also works. However, it does not work by parameter names, but when the order of parameters you add to [the Command] matches. If you change the parameter addition order, [B] will not work. – Ch. W. Lee Dec 14 '21 at 05:42
  • Which programming environment are you using? – jarlh Dec 14 '21 at 07:11
  • C#, Visual Studio 2022 and MimerSQL.Data.Provider( https://www.nuget.org/packages/MimerSQL.Data.Provider/ ). – Ch. W. Lee Dec 14 '21 at 08:28
  • You can also try ordering the parameters, like `WHERE currency_code = :2 AND code = :1` if you want to provide code value first. – jarlh Dec 14 '21 at 14:27
  • My concern is binding query parameters to SQL by name. – Ch. W. Lee Dec 14 '21 at 17:43

0 Answers0