项目杂记(MONTHS_BETWEEN,Having ,Spool)

1,oracle中计算年龄:

select FLOOR(MONTHS_BETWEEN(SYSDATE, to_date('20130728', 'yyyymmdd')) / 12),
trunc(months_between(sysdate, to_date('20130728', 'yyyymmdd')) / 12, 0) from dual;

 

2,用EL表达式去变量Map集合,

例1,

List<String> list = new ArrayList<String>();
list.add("first");
list.add("second");
List<String> list2 = new ArrayList<String>();
list2.add("aaaaaa");
list2.add("bbbbbb");
Map<String,List<String>> map = new HashMap();//(List<Map(k,v)>同理)
map.put("a",list);
map.put("b",list2);
request.setAttribute("map",map);
%>
   通过键获得列表值,并遍历列表<br>
<c:forEach var="item" items="${map['a']}">
${item }<br>
</c:forEach><br>

例2:

${statIssueModel.issues['A2'].toSum};(在statIssueModel中,取得Map集合issues,取得键对应model中toSum属性,issues['A2'].toSum)

 

3,使用hibernate hql语句时候,如果使用多个 select from where, 则会报错如括号不匹配 ")",在使用复杂select语句的时候,最好使用原生态sql语句

 

4,在使用List.toArray()的时候,他会自动把list转成一个Object[]形式数组,对每条list里储存数据,也用自动转换成Object[]数组。

例子:Object[] tols=List.toArray();     (BigeDecimal) ((Object[])tols[0])[1]  ----取得list(0)中第一个元素,转型成BigeDecimal

 

5,having 可以对group by 之后的查询结果,再次进行过滤。

  对多分组统计,可以使用case when then end 语句,oracle 时间格式化:小时用hh24, 分钟用mi

 例子:

select sum(case when t.marry_status=0 then 1 else 0 end) c1,    sum(case when t.marry_status=1 then 1 else 0 end) c2,  t.marry_cert_organ c3,
     from marry_certify_print t    where  t.marry_cert_date>to_date('2011-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss')
          group by t.marry_cert_organ ,to_char(t.marry_cert_date,'yyyy-MM')

 

6,oracle数据导出大量数据的时候,可以使用  "spool","rpad","||"  关键字,写脚本自动执行:

列子:

set termout off;
set heading off;
set pagesize 0;
set verify off;
set echo off;
spool  "d:\hy\lhhy\2002lh.txt";
select
rpad(nvl(trim((select name from  dic_hy_certtype where id=c.M_CERT_TYPE)),''),20,' ')||
rpad(nvl(decode(length(c.M_CERT_ID),18,substr(c.m_cert_id,0,14)||'****',substr(c.m_cert_id,0,length(c.M_CERT_ID)-1)||'*'),' '),30,' ') ||
rpad(nvl(substr(c.m_name,'0','1'),' '),15,' ') ||.....................................................

7,把DIV显示在一行:

在div中加上   style="float: left" 即可。

 

 

posted @ 2013-07-24 10:05  Little_cheeper  阅读(341)  评论(0编辑  收藏  举报