我正在尝试将变量传递给sql脚本并使用c#运行。
我收到错误说
“缺少表达”。
fromDate和toDate以'dd // mm // yy格式传递。我没有使用OracleCommand同时传递参数吗?
public void TransactionReport(string fromDate, string toDate)
{
string query = "select s.store_code,count(i.invc_sid) as count from invoice_v i Left join store_v s ON i.sbs_no = s.sbs_no and i.store_no = s.store_no Where(i.created_date between to_date(@fromDate,'MM//DD//YY') and to_date(@toDate,'MM//DD//YY')) and i.proc_status not in ('131072','65536','147456', '81920') and i.invc_type = 0 AND i.sbs_no = 6 GROUP BY s.store_code";
conn.Open();
using (OracleCommand cmd = new OracleCommand(query, conn))
{
cmd.Parameters.Add(new OracleParameter("fromDate", fromDate));
cmd.Parameters.Add(new OracleParameter("toDate", toDate));
OracleDataReader dr = cmd.ExecuteReader();
答案 0 :(得分:0)
尝试使用:
代替@
string query = "select s.store_code,count(i.invc_sid) as count from invoice_v i Left join store_v s ON i.sbs_no = s.sbs_no and i.store_no = s.store_no Where(i.created_date between to_date(:fromDate,'MM//DD//YY') and to_date(:toDate,'MM//DD//YY')) and i.proc_status not in ('131072','65536','147456', '81920') and i.invc_type = 0 AND i.sbs_no = 6 GROUP BY s.store_code";
答案 1 :(得分:0)
在Oracle中你不应该使用sign @,这只是在SQL Server中,只删除@,它会起作用...