我正在尝试从C#执行Oracle过程,但是ExecuteReader
抛出错误:
ORA-01840:输入值的日期格式不够长。
如果我在WHERE子句中使用“数据已刻录”执行该过程,则效果很好,但在WHERE子句使用参数时却无法正常工作。
这可以:
rigrif.rig_dmov BETWEEN TO_DATE('03/04/2019', 'dd/MM/yyyy') AND TO_DATE('03/04/2019','dd/MM/yyyy')
这不行:
rigrif.rig_dmov BETWEEN TO_DATE(p_date_from, 'dd/MM/yyyy') AND TO_DATE(p_date_to,'dd/MM/yyyy')
// C#代码
public IEnumerable<StockMovements> GetGeneralStockVega(FilterStockValidator value)
{
List<StockMovements> list = new List<StockMovements>();
try
{
Connection ObjCn = new Connection();
using (OracleConnection connection = new OracleConnection(ObjCn.getConnectionString()))
{
OracleCommand command = new OracleCommand(StoredProcedures.sp_Get_GeneralStockVega, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("p_filial", OracleDbType.Varchar2, 2).Value = "18";
command.Parameters.Add("p_date_from", OracleDbType.Varchar2, 22).Value = "03/04/2019";
command.Parameters.Add("p_date_to", OracleDbType.Varchar2, 22).Value ="04/04/2019";
command.Parameters.Add("p_respuesta", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
connection.Open();
OracleDataReader reader = command.ExecuteReader();
StockMovements objStock = null;
while (reader.Read())
{
objStock = new StockMovements();
objStock.FechaMovimiento = reader["fecha_movimiento"].ToString();
objStock.Almacen = reader["almacen"].ToString();
objStock.CantidadVega = decimal.Parse(reader["cantidad"].ToString());
objStock.Documento = reader["documento"].ToString();
list.Add(objStock);
}
}
return list;
}
catch (Exception ex)
{
Logs.RegError(ex, this.GetType());
return null;
}
}
程序代码:
PROCEDURE get_vega_general_stock (
p_date_from IN VARCHAR2,
p_date_to IN VARCHAR2,
p_filial IN VARCHAR2,
p_respuesta OUT SYS_REFCURSOR
)
IS
BEGIN
OPEN p_respuesta FOR
SELECT
TRUNC(rigrif.rig_dmov) AS fecha_movimiento,
rigrif.rig_fili AS almacen,
rigrif.rig_mag AS almacen_office,
testrif.tst_doc AS documento,
SUM(rigrif.rig_qta) AS cantidad
FROM
rigrif rigrif
INNER JOIN detrif detrif
ON rigrif.rig_det = detrif.det_prg
INNER JOIN prodotti prodotti
ON rigrif.rig_pro = prodotti.pro_cod
INNER JOIN testrif testrif
ON rigrif.rig_testrif = testrif.tst_prg
WHERE
detrif.det_del = 'E'
AND prodotti.pro_grp = 0
AND rigrif.rig_fili = '18'
AND rigrif.rig_dmov BETWEEN TO_DATE(p_date_from, 'dd/MM/yyyy' ) AND TO_DATE(p_date_to,'dd/MM/yyyy')
GROUP BY
TRUNC(rigrif.rig_dmov),
rigrif.rig_fili,
rigrif.rig_mag,
testrif.tst_doc
ORDER BY
1,2,3,4;
END get_vega_general_stock;