如何在oracle / sql中验证日期? [英] How can i validate date in oracle /sql ?
问题描述
嗨
在我的表中,我有一个字段'FLD_DATE'。我想根据'FLD_DATE'字段获取记录。
i想要根据日期间隔记录记录。
即
如果我将01 / jan / 2013作为我的日期提交,那么我将采取从2013年1月1日开始的日期记录。
我怎么能这样做?
Hi
In my table i have one field 'FLD_DATE' . I want to fetch the records based on 'FLD_DATE' field.
i want to take the records based on date intervel.
that is,
if i give 01/jan/2013 as my date filed then i hvae to take the records which have date starting from 01/jan/2013.
How can i do this??
推荐答案
Hello Gayathri,
假设FLD_DATE属于DATE类型,您可以编写一个简单的选择查询来检索数据。下面的示例显示了如何在oracle中编写此类查询。
Hello Gayathri,
Assuming FLD_DATE is of type DATE you can write a simple select query to retrieve the data. The below example shows how you can write such query in oracle.
SELECT * FROM YOUR_TABLE WHERE FLD_DATE >= TO_DATE('01/JAN/2013', 'DD/MON/YYYY')
如果从.NET前端调用此查询,那么您将使用 DBCommand
,在这种情况下,字符串值(用户输入)将是第一个转换为Date类型变量,然后该转换后的值将作为参数传递给 DBCommand
。下面的代码段显示了如何使用 Oracle Data Provider for .NET 在C#中完成此操作[ ^ ]。
If you are calling this query from .NET front-end then you will be using DBCommand
in which case the string value(User Input) will be first converted to a Date type variable and then that converted value will be passed to the DBCommand
as a parameter. Below snippet shows how it can be done in C# using Oracle Data Provider for .NET[^].
OracleConnection con;
OracleCommand cmd;
OracleParameter prm;
OracleDataReader reader;
con = new OracleConnection();
con.ConnectionString = "User Id=scott;Password=tiger;Data Source=oracle";
con.Open();
cmd = new OracleCommand("SELECT * FROM TABLE_FOO WHERE fld_date >= :filtDate");
prm = new OracleParameter("filtDate", OracleDbType.Varchar2);
prm.Direction = ParameterDirection.Input;
prm.value = dtFilter;
cmd.Parameters.Add(prm);
reader = cmd.ExecuteReader();
// Code for reading the records
reader.Dispose();
cmd.Dispose();
问候,
Regards,
这篇关于如何在oracle / sql中验证日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!