以下是我尝试使用 oracle 连接字符串在我的 C# 代码中运行的命令,一切都很好(相同的查询在 toad 中运行顺利)。然而,在填充数据集时,它给出了 ORA-00911 的错误:无效字符。我不知道为什么,请帮忙。
OracleCommand cmd = new OracleCommand(
"SELECT DSAT.ORGANIZATION_ID, APPS.DAW_INV_ORG_NAME(DSAT.ORGANIZATION_ID) ORGANIZATION_NAME,APPS.DAW_CAT_NAME(MC.SEGMENT4) PRODUCT,TRUNC(NVL(DSAT.SCH_END_DATE,DSAT.SCH_START_DATE)) TRANSACTION_DATE,"
+"TO_CHAR(NVL(DSAT.SCH_END_DATE,DSAT.SCH_START_DATE),'MM-YYYY') MONTH,DSAT.ITEM_SEGMENTS ITEM_CODE, DSAT.ITEM_DESCRIPTION,"
+"DSAT.CURRENT_FORECAST_QUANTITY PLAN_QTY FROM APPS.DAW_SCPDB_ASCP_TPP_V DSAT,APPS.MTL_ITEM_CATEGORIES MIC,"
+"APPS.MTL_CATEGORIES MC"
+ " WHERE NVL(SCH_END_DATE,SCH_START_DATE) BETWEEN TO_DATE(@vfrom,'dd/mm/yyyy') AND TO_DATE(@vto,'dd/mm/yyyy')"+
" AND MIC.CATEGORY_SET_ID=1100000061 AND MC.CATEGORY_ID=MIC.CATEGORY_ID AND DSAT.INVENTORY_ITEM_ID=MIC.INVENTORY_ITEM_ID"
+" AND DSAT.ORGANIZATION_ID=MIC.ORGANIZATION_ID"
+" AND DSAT.FORECAST_SET IN (@vForecastSetDPL1,@vForecastSetDPL2,@vForecastSetURIL)"
+" AND APPS.DAW_CAT_NAME(MC.SEGMENT4) ='MICRO WAVE OVEN';", con);
cmd.Parameters.Add("@vfrom",OracleDbType.Varchar2).Value= vfrom;
cmd.Parameters.Add("@vto",OracleDbType.Varchar2).Value= vto;
cmd.Parameters.Add("@vForecastSetDPL1", OracleDbType.Varchar2).Value=vForecastSetDPL1;
cmd.Parameters.Add("@vForecastSetDPL2",OracleDbType.Varchar2).Value=vForecastSetDPL2;
cmd.Parameters.Add("@vForecastSetURIL",OracleDbType.Varchar2).Value= vForecastSetURIL;
cmd.CommandType = CommandType.Text;
使用的所有变量都是字符串类型,因此对于日期,我必须使用 TO_DATE。其余参数应该是字符串类型。