日期参数在SQL与FineReport中的处理
2012-09-07 00:23
411 查看
在如今各式各样的数据库中,对时间类型的数据处理也不尽相同。要将FineReport中的时间类型数据与数据库中的时间类型数据对接,必须借助一些格式转换函数。
在此,以常用的数据库Oracle和SQL Server为例,举例讲述其与FineReport之间时间类型的转换,同FR使用者们共同交流。
Oracle and FineReport
例如:
Oracle数据库中有名为example的数据表,表中有名为Date的时间字段,FineReport中有一个时间参数a;现要求选出example表中Date字段与参数a相等的记录。
分情况转换方法如下表所示:
SQL Server and FineReport
例如:
Oracle数据库中有名为example的数据表,表中有名为Date的时间字段,FineReport中有一个时间参数a;现要求选出example表中Date字段与参数a相等的记录。(SQL Server中对不同的时间格式都有对应的不同公式写法)
日期参数对应关系如下表所示:
在此,以常用的数据库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') |
例如:
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) |
相关文章推荐
- ORACLE 关于一些日期处理的sql
- SQL常用日期处理
- sql日期处理
- sql的分组统计与group by 日期的处理
- SQL:数据库日期处理
- 存储过程中特殊符号的处理-sql语句当参数的存储过程-复杂查询
- oracle trunc 函数处理日期格式,日期类型很有用的几个sql
- 2.3.4 SET LANGUAGE对日期处理的影响示例.sql
- 42.Oracle数据库SQL开发之 日期和时间的存储与处理——Oracle对2位年份处理
- sql 传入参数为逗号分隔的字符串处理方法
- SQL处理日期
- sql中处理日期类型
- SQL常用日期处理函数
- sqlserver 针对预处理sql传入参数的处理方式
- sql日期时间处理集合
- sql日期格式处理
- SQL日期处理
- 质量Q图关键SQL研究-对日期数据的处理
- 2.4.1 日期格式化处理.sql
- 理解java.sql和java.text包---日期处理相关