在如今各式各樣的數據庫中,對時間類型的數據處理也不盡相同。要將FineReport中的時間類型數據與數據庫中的時間類型數據對接,必須借助一些格式轉換函數。
在此,以常用的數據庫Oracle和SQL Server為例,舉例講述其與FineReport之間時間類型的轉換,同FR使用者們共同交流。
Oracle and FineReport
例如:
Oracle數據庫中有名為example的數據表,表中有名為Date的時間字段,FineReport中有一個時間參數a;現要求選出example表中Date字段與參數a相等的記錄。
分情況轉換方法如下表所示:
Oracle | FineReport | SQL語法 |
日期類型字段 Date(yyyy-MM-dd) | 時間類型參數a /字符串類型參數a | Select * from example where Date=to_date('${a}','yyyy-MM-dd') |
字符串類型字段 Date(MM/dd/yyyy) | 時間類型參數a /字符串類型參數a | Select * from example where Date=to_char('${a}','MM/dd/yyyy') |
時間類型字段 Date(yyyy MM dd hh24:mi:ss) / (yyyy MM dd hh12:mi:ss) | 時間類型參數a /字符串類型參數a | Select * from example where Date=to_char('${a}','yyyy MM dd hh24:mi:ss') / Select * from example where Date=to_char('${a}','yyyy MM dd hh12:mi:ss') |
字符串類型字段 Date(yyyy.MM.dd hh24:mi:ss) / (yyyy.MM.dd hh12:mi:ss) | 時間類型參數a /字符串類型參數a | Select * from example where Date=to_char('${a}','yyyy.MM.dd hh24:mi:ss') / Select * from example where Date=to_char('${a}','yyyy.MM.dd hh12:mi:ss') |
SQL Server and FineReport
例如:
Oracle數據庫中有名為example的數據表,表中有名為Date的時間字段,FineReport中有一個時間參數a;現要求選出example表中Date字段與參數a相等的記錄。(SQL Server中對不同的時間格式都有對應的不同公式寫法)
日期參數對應關系如下表所示:
SQL Server | FineReport | SQL語法 |
Date (mon dd yyyy hh:miAM/ PM) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 0) / Select * from example where Date= CONVERT(varchar(100), ${a}, 100) |
Date(mm/dd/yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 1) |
Date(yy.mm.dd) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 2) |
Date(dd/mm/yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 3) |
Date(dd.mm.yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 4) |
Date(dd-mm-yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 5) |
Date(dd mon yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 6) |
Date(mon dd, yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 7) |
Date(hh:mm:ss) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 8) / Select * from example where Date=CONVERT(varchar(100), ${a}, 108) |
Date (mon dd yyyy hh:mi:ss:mmmAM/ PM) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 9) / Select * from example where Date=CONVERT(varchar(100), ${a}, 109) |
Date(mm-dd-yy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 10) |
Date(yy/mm/dd) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 11) |
Date(yymmdd) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 12) |
Date (dd mon yyyy hh:mm:ss:mmm(24h)) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 13) / Select * from example where Date=CONVERT(varchar(100), ${a}, 113) |
Date(hh:mi:ss:mmm(24h)) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 14) / Select * from example where Date=CONVERT(varchar(100), ${a}, 114) |
Date (yyyy-mm-dd hh:mm:ss[.fff]) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 20) / Select * from example where Date=CONVERT(varchar(100), ${a}, 120) |
Date (yyyy-mm-dd hh:mm:ss[.fff]) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 21) / Select * from example where Date=CONVERT(varchar(100), ${a}, 121) |
Date(mm/dd/yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 101) |
Date(yyyy.mm.dd) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 102) |
Date(dd/mm/yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 103) |
Date(dd.mm.yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 104) |
Date(dd-mm-yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 105) |
Date(dd mon yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 106) |
Date(Mon dd, yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 107) |
Date(mm-dd-yyyy) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 110) |
Date(yyyy/mm/dd) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 111) |
Date(yyyymmdd) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 112) |
Date (yyyy-mm-ddThh:mi:ss.mmm (no spaces)) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 126) |
Date (yyyy-mm-ddThh:mi:ss.mmmZ (no spaces)) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 127) |
Date (dd mon yyyy hh:mi:ss:mmmAM) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 130) |
Date (dd/mm/yy hh:mi:ss:mmmAM) | 時間類型參數a / 字符串類型參數a | Select * from example where Date=CONVERT(varchar(100), ${a}, 131) |
了解Java報表工具就從這里開始