OracleCommand 未正确结束

OracleCommand not ended properly

我有一个查询来检查用户是否存在于数据库中。当我通过 OracleCommand 检查此查询时,它会导致异常并显示 command 未正确结束。

这里是查询:

select count(*) as user_exists
 from users
  where upper(u_name) = upper('name')
  and u_password = DB_PKG_ACCESS.f_encrypt('pass')
  and (expiration_date is null or (expiration_date is not null and trunc(expiration_date) >= trunc(sysdate)));

这里是 command:

OracleCommand cmd = new OracleCommand("select count(*) as user_exists from users where upper(u_name) = upper('name')"
       +" and u_password = DB_PKG_ACCESS.f_encrypt('pass')"
       +" and(expiration_date is null or(expiration_date is not null and trunc(expiration_date) >= trunc(sysdate)));", con);
cmd.Parameters.Add(new OracleParameter("name", textBox1.Text));
cmd.Parameters.Add(new OracleParameter("pass", textBox2.Text));

我哪里错了?

尝试像这样从 OracleCommand 中的语句末尾取出分号

OracleCommand cmd = new OracleCommand("select count(*) as user_exists from users where upper(u_name) = upper('name')"
       +" and u_password = DB_PKG_ACCESS.f_encrypt('pass')"
       +" and(expiration_date is null or(expiration_date is not null and trunc(expiration_date) >= trunc(sysdate)))   ", con);

我以前也遇到过这个问题....

HTH

尝试去掉查询中的分号(命令对象自动结束)

OracleCommand cmd = new OracleCommand("select count(*) as user_exists from users where upper(u_name) = upper('name')"
   +" and u_password = DB_PKG_ACCESS.f_encrypt('pass')"
   +" and(expiration_date is null or(expiration_date is not null and trunc(expiration_date) >= trunc(sysdate))); <==== Here remove it", con);