这毁了我。...
我有一个Oracle过程,如下所示:(这是我的最新版本)
create or replace PROCEDURE MANAGEMENTFEES
(
STARTDATE IN VARCHAR2
, ENDDATE IN VARCHAR2
, cursor_ OUT sys_refcursor
) AS
BEGIN
OPEN cursor_ FOR
select PR.PRNUM
FROM MAXIMO.PR
WHERE PR.ISSUEDATE > to_date(STARTDATE) AND PR.ISSUEDATE < to_date(ENDDATE)
END MANAGEMENTFEES;
我正在使用以下.Net代码对其进行查询。
OracleConnection connection = getConnection();
connection.Open();
string startDate = new DateTime(2019, 1, 1).ToString("dd-MMM-yy");
string endDate = new DateTime(2019, 5, 1).ToString("dd-MMM-yy");
OracleDataAdapter da = new OracleDataAdapter();
OracleCommand cmd = new OracleCommand();
cmd.Connection = connection;
cmd.CommandText = "ORACLE.MANAGEMENTFEES";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("STARTDATE", OracleDbType.Varchar2).Value =startDate;
cmd.Parameters.Add("ENDDATE", OracleDbType.Varchar2).Value = endDate;
cmd.Parameters.Add("cursor_", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
这给了我一个空白的数据表,但是它确实有标题。所以这告诉我查询只是没有得到任何结果。我一直在使用多个stackoverflow答案来更改日期参数,但是却无处可寻。
如果我在过程中对日期进行硬编码,则可以正常工作,但是我希望能够传递不同的日期。
帮助?
更新-添加带有硬编码日期的代码
create or replace PROCEDURE MANAGEMENTFEES
(
STARTDATE IN DATE
, ENDDATE IN DATE
, cursor_ OUT sys_refcursor
) AS
BEGIN
OPEN cursor_ FOR
select PR.PRNUM
FROM MAXIMO.PR
WHERE PR.ISSUEDATE > '01-JAN-19' AND PR.ISSUEDATE < '01-MAY-19'
ORDER BY ISSUEDATE ASC;
END MANAGEMENTFEES;
答案 0 :(得分:1)
您的过程应如下:
create or replace PROCEDURE MANAGEMENTFEES
(
STARTDATE IN DATE
, ENDDATE IN DATE
, cursor_ OUT sys_refcursor
) AS
BEGIN
OPEN cursor_ FOR
select PR.PRNUM
FROM MAXIMO.PR
WHERE PR.ISSUEDATE > STARTDATE AND PR.ISSUEDATE < ENDDATE
END MANAGEMENTFEES;
.NET中的调用将是这样:
DateTime startDate = new DateTime(2019, 1, 1);
DateTime endDate = new DateTime(2019, 5, 1);
...
cmd.Parameters.Add("STARTDATE", OracleDbType.Date).Value = startDate;
cmd.Parameters.Add("ENDDATE", OracleDbType.Date).Value = endDate;
答案 1 :(得分:0)
现在已解决此问题,这是由于使用了Oracle保留的STARTDATE
和ENDDATE
(尽管未引发任何错误)引起的。
将它们更改为v_STARTDATE
和v_ENDDATE
解决了该问题。