簡體   English   中英

如何僅輸入月份和年份從 oracle 中獲取 select 日期值?

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

我正在嘗試根據月份和年份從 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

我在使用此查詢的 ASP 中遇到語法錯誤。

請任何人都可以幫助我。

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

如果您不想繞過表索引並進行全表掃描,這應該對您有用。

(來源:如何 select 特定月份的行

您也可以轉換為月份和年份組合,如下所示 -

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

或者如果你想在 clouse 之間進行檢查,那么你必須像下面的查詢那樣做

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

代替 &mon &year 你必須給出你的變量名。

@Miroprocessor 你不能申請 to_date ('31 '+input+.........

在動態性質查詢中,您不會總是只找到 10 月,而在 oracle 數據庫中,此查詢將給出 JUN 或 FEB 月的錯誤...

你可以測試這個東西 oracle 數據庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM