oracle时间格式

Timestamp 格式时间

最常用方法:

to_timestamp('2013-06-04 12:22:10.1','yyyy-mm-dd hh24:mi:ss.ff')

 

时间加减:

单位小于天用 numtodsinterval

select sysdate, sysdate+numtodsinterval(1,’hour’) from dual ;

单位大于天 直接用 +1 (+1天)

 

时间截取方法 TRUNC

TRUNC(SYSDATE,'HH') = 2014-02-20 17:00:00

截取字符串函数

substr( string, start_position, [ length ] )

连接两个字符串

concat(str1,str2);

偏移量函数

lead(t.col_value,1,null) over(partition by t.tch_id order by t.col_value)

注:lead函数是先按tch_id分组,按col_val排序,并把当前行col_value的下一个值放到sal中,比如: 

col_value=10的下一个值是14,col_value=14 的下一个值是20。函数中的null是当没有下一个值时用null代替,当然也可以用其他值替换NULL. 

PS:lead 是向下偏移 lag 是向上偏移

oracle带参数的游标

declare cursor mysor(proname varchar2) is

select  from sys_pro_monitor where pro_name=proname;

c_row mysor%rowtype;

begin

 open mysor('PRO_RPT_KPI') ;

 loop

   fetch mysor into c_row;

   exit when mysor%notfound;

   dbms_output.put_line(c_row.id);

 end loop;

end;

猜你喜欢

转载自maple-xf.iteye.com/blog/1881996