大家好,
我在使用 SQL 查詢時遇到一些困難。 我的目標是使用日曆 box() 函數中的用戶定義日期來修改每個 sql 查詢以從這些日期範圍之間提取數據。 這是日曆框的代碼:
Cancel = "0";
New Window( "ZFG Cycle Start Date",
<<Modal,
cal1 = Calendar Box(),
cal1 << Show Time(0);
Button Box( "OK", cal2 = cal1 << get date;),
Button Box( "Cancel", Cancel = "1") );
cal3 = MDYHMS(cal2);
If(Cancel =="1", Stop());
New Window( "ZFG Cycle End Date",
<<Modal,
cal4 = Calendar Box(),
cal4 << show time(0);
Button Box( "OK", cal5 = cal4 <<get date;),
Button Box( "Cancel", Cancel = "1") );
If(Cancel =="1", Stop());
cal6 = mdyhms(cal5);
這是我的 SQL 查詢代碼。 我突出顯示了代碼崩潰的地方:
sql_script = evalinsert(
"SELECT *
FROM OHT_MOVES_FLATFILE
Where day <= To_Date('^cal6^', 'M/D/Y')
and day >= To_Date('^cal3^', 'MDY')
and vehicle_type = 'FOUP'
and dst_tool= ANY('ZFG1_17C01','ZFG1_17C02', 'ZFG1_17W01', 'ZFG_17W02')
and rownum <100000
Order by request_time");當我以這種格式手動輸入日期時,它運行良好:
day <= To_Date('07/17/2017', 'MM/DD/YYYY')
使用 calenderbox() 中的變量,返回以下錯誤之一,具體取決於我嘗試設置它的方式。 日曆框變量將以這種格式返回日期:“07/17/2017 2:07:14 PM”
[Oracle][ODBC][Ora]ORA-01843: not a valid month
[Oracle][ODBC][Ora]ORA-01830: date format picture ends before converting entire input string
你們的任何建議將不勝感激
您必須從日期中刪除時間戳,以便 Oracle 正確處理它。
cal3 = substr(MDYHMS(cal2), 1, 10);
cal6 = substr(mdyhms(cal5), 1, 10);
或者,如果您想要更精細,您可以提供適當的日期/時間格式以包括時間。