Add date parameter to oracle query

后端 未结 1 1547
有刺的猬
有刺的猬 2020-12-21 17:51

What I\'m trying to do is to execute the query between two dates, and the dates would come from a parameter.

In the below code, I\'m putting one parameter and lettin

相关标签:
1条回答
  • 2020-12-21 18:02

    I didn't find a way to do it using Varchar2 Datatype. So, I'm giving the answer using Date Datatype.

    if (dateTo.Minute > 30)
       minToInt = 30;
    else
       minToInt = 00;
    
    dateFrom = DateTime.Now;
    dateTo = DateTime.Now;     
    
    DateTime dateFrom = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, dateFrom.Hour, 00, 00);
    DateTime dateTo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, dateTo.Hour, minToInt, 00);
    
    ////////FROM DATE/////////
    OracleParameter fromDateParameter = new OracleParameter();
    fromDateParameter.OracleDbType = OracleDbType.Date;
    fromDateParameter.Value = dateFrom;
    
    ////////TO DATE/////////
    OracleParameter toDateParameter = new OracleParameter();
    toDateParameter.OracleDbType = OracleDbType.Date;
    toDateParameter.Value = dateTo;
    
    
    this.oracleDataAdapter4.SelectCommand = new OracleCommand("
       SELECT DISTINCT (LOG.RID) FROM LOG WHERE LOG.TIMESTAMP 
       BETWEEN :fromDateParameter 
       AND :toDateParameter)", oracleConnection4);
    
    oracleDataAdapter4.SelectCommand.Parameters.Add(fromDateParameter);           
    oracleDataAdapter4.SelectCommand.Parameters.Add(toDateParameter);  
    this.oracleDataAdapter4.Fill(event11);
    

    Don't get confuse with the if/else minute validation, it is just for my query purpose.

    0 讨论(0)
提交回复
热议问题