我有一个查询,检查用户是否存在于数据库中。当我通过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));
我哪里错了?
答案 0 :(得分:2)
尝试从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
答案 1 :(得分:2)
尝试在查询中删除分号(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))); <==== Here remove it", con);