简体   繁体   English

如何仅输入月份和年份从 oracle 中获取 select 日期值?

[英]how to select date value from oracle with only Month and Year as inputs?

I am trying to retrieve date value from oracle based on month and year only like OCT 2009 is the input, I want to display on my web page all the days for this month and year only...我正在尝试根据月份和年份从 oracle 检索日期值,仅像 OCT 2009 是输入,我想在我的 web 页面上显示本月和本年的所有日期...

else if trim(cdate) <>"" then
            strQuery1 = "select rowid,Year, Name, Loca, cdate, Net_ty, eq_ty, working, ser_code, circuit_name, line_ref, no_fault from asset_hdsl where trunc(cdate,'Mon-YYYY')="
            strQuery1 = strQuery1 & "'" & to_date(cdate,'Mon-YYYY') & "'"
     response.write strQuery1

I am getting syntax errors in ASP with this query.我在使用此查询的 ASP 中遇到语法错误。

Please can anyone help me out.请任何人都可以帮助我。

    WHERE
   enddate>=date '2009-10-01' and enddate<date '2009-11-01';

This should work for you if you don't want to bypass table index and do a full table scan.如果您不想绕过表索引并进行全表扫描,这应该对您有用。

(src: How to select rows for a specific month ) (来源:如何 select 特定月份的行

you can convert to Month and Year combination also as follow--您也可以转换为月份和年份组合,如下所示 -

Select * from MyTable where to_char(MyDate,'MON YYYY') = upper('&mon &year');

or if you want to check with between clouse then you have to do like below query或者如果你想在 clouse 之间进行检查,那么你必须像下面的查询那样做

SELECT * from MyTable WHERE MyDate between trunc(to_date('&mon &year','MON YYYY'),'MON') and last_day(to_date('&mon &year','MON YYYY'));

In place of &mon &year you have to give your variable name.代替 &mon &year 你必须给出你的变量名。

@Miroprocessor you can't apply to_date ('31 '+input+......... @Miroprocessor 你不能申请 to_date ('31 '+input+.........

in dynamic nature query you will not always find for Oct month only and in oracle database this query will give error for say JUN or FEB month...在动态性质查询中,您不会总是只找到 10 月,而在 oracle 数据库中,此查询将给出 JUN 或 FEB 月的错误...

you can test on this things oracle database你可以测试这个东西 oracle 数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM