我有一个查询,可以检查数据库中是否存在用户。当我通过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));
我错在哪里?
尝试像
这样从 Oracle 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);
这对我来说以前一直是一个问题。
呵呵
尝试删除查询中的分号(命令对象会自动结束(
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);