错误说";缺少右括号";在我的SQL语句中..但它';s不是!帮助
本文关键字:quot 但它 语句 帮助 SQL 不是 错误 我的 | 更新日期: 2023-09-27 18:04:19
这是我的C#程序中的语句:
(由gbn编辑,为清晰起见格式化,因此不在一行上所有(
DbCommand.CommandText =
@"SELECT
HIST.MBRSEP, HIST.LOCATION, HIST.BILLTYPE, HIST.BILLMOYR, LOCINFO.CYCLE,
LOCINFO.DIST, LOCINFO.LOCATION
FROM
(CAV_MBRHISTDEL AS HIST INNER JOIN CAV_LOCINFODETL AS LOCINFO ON HIST.LOCATION = LOCINFO.LOCATION)
WHERE
LOCINFO.CYCLE = @CYCLE AND
LOCINFO.DIST = @DISTRICT AND
HIST.BILLTYPE = '09' AND
HIST.BILLMOYR <> '9999'";
这是错误消息:
错误[HY000][Oracle][ODBC][Ora]Ora-00907:缺少右括号
在我的SQL语句中只有两个括号,一个右括号和一个左括号。我不知道这个错误告诉我什么。有什么建议吗?
编辑:以下是参数的定义方式:
string cycle = cbCycle.Text;
string district = cbDistrict.Text.Substring(0,2);
这里是我将它们添加到DbCommand:的地方
DbCommand.Parameters.AddWithValue("@CYCLE", cycle);
DbCommand.Parameters.AddWithValue("@DISTRICT", district);
以下是我的完整代码,当有人点击我表单上的"Go"按钮时会触发:
private void btnGo_Click(object sender, EventArgs e)
{
//get parameters
string cycle = cbCycle.Text;
string district = cbDistrict.Text.Substring(0,2);
//create a connection to the database
OdbcConnection DbConnection = new OdbcConnection("DSN=UPN2;uid=xxx;pwd=xxxx");
DbConnection.Open();
//create a command to extract the required data and
//assign it to the connection string
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText =
@"SELECT HIST.MBRSEP, HIST.LOCATION, HIST.BILLTYPE, HIST.BILLMOYR, LOCINFO.CYCLE, LOCINFO.DIST, LOCINFO.LOCATION FROM CAV_MBRHISTDEL AS HIST INNER JOIN CAV_LOCINFODETL AS LOCINFO ON HIST.LOCATION = LOCINFO.LOCATION WHERE LOCINFO.CYCLE = @CYCLE AND LOCINFO.DIST = @DISTRICT AND HIST.BILLTYPE = '09' AND HIST.BILLMOYR <> '9999'; ";
DbCommand.Parameters.AddWithValue("@CYCLE", cycle);
DbCommand.Parameters.AddWithValue("@DISTRICT", district);
//Create a DataAdapter to run the command and fill the datatable
OdbcDataAdapter da = new OdbcDataAdapter();
da.SelectCommand = DbCommand;
DataTable dt = new DataTable();
da.Fill(dt);
tbOutput.Text = PrintDataTable(dt);
DbCommand.Dispose();
DbConnection.Close();
}
问题可能是您将oracle保留字用作列名和参数名,即CYCLE
。。。这样做可能会导致DB出现奇怪和不稳定的行为!
参见http://download.oracle.com/docs/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm
根据数据库提供程序的不同,您可能希望使用:
而不是@
作为参数。
试着去掉你的括号:你不需要它们。
内部查询中缺少SELECT
。试试这个:
...
FROM
(SELECT CAV_MBRHISTDEL AS HIST -- Added SELECT
INNER JOIN CAV_LOCINFODETL AS LOCINFO ON HIST.LOCATION = LOCINFO.LOCATION)
WHERE
...
您有:
FROM
(CAV_MBRHISTDEL ... -- Missing SELECT