oracle中add_months和trunc用法

本文详细介绍了Oracle数据库中处理日期和时间的多种函数,包括ADD_MONTHS函数用于获取指定时间前后几个月的日期,TRUNC函数用于截取日期或数值。此外还提供了大量示例帮助理解这些函数的具体应用。

oracle add_months(time,months)函数可以得到某一时间之前或之后n个月的时间

  1. 如 select add_months(sysdate,-6) from dual; 

该查询的结果是当前时间半年前的时间

  1. select add_months(sysdate,6) from dual; 

该查询的结果是当前时间半年后的时间

  1. my examle:  
  2. select distinct(t.mobile) from twaplogon t where to_char(t.logontime,'yyyy-mm')=to_char(add_months(sysdate,-1),'yyyy-mm') 

以上就是oracle add_months函数的使用方法

1.TRUNC(for dates)
TRUNC函数为指定元素而截去的日期值。
其具体的语法格式如下:
TRUNC(date[,fmt])
其中:
date 一个日期值
fmt 日期格式,该日期将由指定的元素格式所截去。忽略它则由最近的日期截去
下面是该函数的使用情况:
TRUNC(TO_DATE(’24-Nov-1999 08:00 pm’,’dd-mon-yyyy hh:mi am’))
=’24-Nov-1999 12:00:00 am’
TRUNC(TO_DATE(’24-Nov-1999 08:37 pm’,’dd-mon-yyyy hh:mi am’,’hh’)) =’24-Nov-1999 08:00:00 am’

round (date,''format'')未指定format时,如果日期中的时间在中午之前,则将日期中的时间截断为12 A.M.(午夜,一天的开始),否则进到第二天。

TRUNC(date,''format'')未指定format时,将日期截为12 A.M.,不考虑是否在中午之前的条件。

2.TRUNC(for number)
TRUNC函数返回处理后的数值,其工作机制与ROUND函数极为类似,只是该函数不对指定小数前或后的部分做相应舍入选择处理,而统统截去。
其具体的语法格式如下
TRUNC(number[,decimals])
其中:
number 待做截取处理的数值
decimals 指明需保留小数点后面的位数。可选项,忽略它则截去所有的小数部分
下面是该函数的使用情况:
TRUNC(89.985,2)=89.98
TRUNC(89.985)=89
TRUNC(89.985,-1)=80
注意:第二个参数可以为负数,表示为小数点左边指定位数后面的部分截去,即均以0记。

{


format为day时,只精确到天,而不管几年几月只要是符合的day就可以了,要想确定一年中的某月的某一天就要用trunc(date,''dd'').

通俗的说吧,format为年时,精确到-----年

为月时,精确到------年,月(不管哪年,只要是相同的月和哪天)
为日时,精确到------年,月,日(不管哪年的哪月,只关心是哪天)


}

///////////////////////////////////////////////////////////////////////////////


实例:


对数字,日期进行的
SQL> select trunc(sysdate) from dual;
TRUNC(SYSD
----------
07-1月 -03
SQL> select trunc(sysdate,'mm') from dual;
TRUNC(SYSD
----------
01-1月 -03
SQL> select trunc(sysdate,'yy') from dual;
TRUNC(SYSD
----------
01-1月 -03
SQL> select trunc(234.5565) from dual;
TRUNC(234.5565)
---------------
234
SQL> select trunc(sysdate,'D') from dual;
TRUNC(SYSD
----------
05-1月 -03

////////////////////////////////////////////////////////////////////////////

select trunc(sysdate ,'dd') from dual ; -- 2007-9-19

select trunc(sysdate ,'yyyy') from dual ; --2007-1-1

select trunc(sysdate ,'mm') from dual ; --2007-9-1


begin
dbms_output.put_line( to_char ( (sysdate) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;
dbms_output.put_line( to_char ( (sysdate)+ 1/24/60/10 , 'yyyy-mm-dd hh24:mi:ss' ) ) ;
dbms_output.put_line( to_char ( ((sysdate)+ 10 / ( 24*60*60 ) ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;

dbms_output.put_line( to_char ( trunc((sysdate)+ 10 / ( 24*60*60 ) ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;

end ;

begin
dbms_output.put_line( '当前时间 ' ) ;
dbms_output.put_line( to_char ( (sysdate) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;

dbms_output.put_line( '当前时间 + 1 s ' ) ;
dbms_output.put_line( to_char ( (sysdate)+ (((1/24)/60)/60 ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;

dbms_output.put_line( '当前时间 + 1 s ' ) ;
dbms_output.put_line( to_char ( (sysdate)+ (((5/24)/60)/60 ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;

dbms_output.put_line( '当前时间 + 10s ' ) ;
dbms_output.put_line( to_char ( ((sysdate)+ ( 10 / ( 24*60*60 )) ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;

dbms_output.put_line( '当前 日 ' ) ;
dbms_output.put_line( to_char ( trunc((sysdate)) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;


dbms_output.put_line( '当前 第2天 1点 ' ) ;
dbms_output.put_line( to_char ( trunc(sysdate)+( 1 + 1/24 ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;


dbms_output.put_line( '当前 第2天 9点 ' ) ;
dbms_output.put_line( to_char ( trunc(sysdate)+( 1 + 9/24 ) , 'yyyy-mm-dd hh24:mi:ss' ) ) ;


end ;
/
////////////////////////////////////////////////////////////////////////////


oracle 日期常用函數 (SYSDATE、日期格式)

1 SYSDATE
2 --◎ 可得到目前系統的時間
3
4 ex.
5 select sysdate from dual;
6
7 sysdate
8 ----------
9 20-SEP-07
10
11 常用之日期格式
12
13 日期格式 說明
14 ------------------------------------------------------------------------
15 YYYY/MM/DD -- 年/月/日
16 YYYY -- 年(4位)
17 YYY -- 年(3位)
18 YY -- 年(2位)
19 MM -- 月份
20 DD -- 日期
21 D -- 星期
22 -- 星期日 = 1 星期一 = 2 星期二 = 3
23 -- 星期三 = 4 星期四 = 5 星期五 = 6 星期六 = 7
24
25 DDD -- 一年之第幾天
26 WW -- 一年之第幾週
27 W -- 一月之第幾週
28 YYYY/MM/DD HH24:MI:SS -- 年/月/日 時(24小時制):分:秒
29 YYYY/MM/DD HH:MI:SS -- 年/月/日 時(非24小時制):分:秒
30 J -- Julian day,Bc 4712/01/01 為1
31 RR/MM/DD -- 公元2000問題
32             -- 00-49 = 下世紀;50-99 = 本世紀
33 ex.
34 select to_char(sysdate,'YYYY/MM/DD') FROM DUAL; -- 2007/09/20
35 select to_char(sysdate,'YYYY') FROM DUAL; -- 2007
36 select to_char(sysdate,'YYY') FROM DUAL; -- 007
37 select to_char(sysdate,'YY') FROM DUAL; -- 07
38 select to_char(sysdate,'MM') FROM DUAL; -- 09
39 select to_char(sysdate,'DD') FROM DUAL; -- 20
40 select to_char(sysdate,'D') FROM DUAL; -- 5
41 select to_char(sysdate,'DDD') FROM DUAL; -- 263
42 select to_char(sysdate,'WW') FROM DUAL; -- 38
43 select to_char(sysdate,'W') FROM DUAL; -- 3
44 select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') FROM DUAL; -- 2007/09/20 15:24:13
45 select to_char(sysdate,'YYYY/MM/DD HH:MI:SS') FROM DUAL; -- 2007/09/20 03:25:23
46 select to_char(sysdate,'J') FROM DUAL; -- 2454364
47 select to_char(sysdate,'RR/MM/DD') FROM DUAL; -- 07/09/20
【--4、去月保费 Execute Immediate 'truncate table jsxs_day_qy1 '; insert into jsxs_day_qy1 select /*+parallel(4) */ level2comcode, level3comcode, riskcode, newchnltype, sum(PREMIUM) PREMIUM, datetype from (select /*+parallel(4) */ b.level2comcode, b.level3comcode, substr(a.RISKCODE, 1, 2) as riskcode, (case when x.newchnltype is null then '00' else x.newchnltype end) newchnltype, (a.PREMIUM * a.EXCHRATE * a.COINSRATE / 100) AS PREMIUM, --原始保费收入 'STATDATE' as datetype FROM WEB_LIST_CMAINORIGIN a, cd_com_all b, ods_cmain x WHERE a.STATDATE between add_months(trunc(sysdate - 1, 'mm'), -12) and add_months(trunc(sysdate - 1), -12) and a.COMCODE = b.comcode and a.policyno = x.policyno(+) UNION ALL select /*+parallel(4) */ d.level2comcode, d.level3comcode, substr(c.RISKCODE, 1, 2) as riskcode, (case when y.newchnltype is null then '00' else y.newchnltype end) newchnltype, (c.CHGPREMIUM * c.EXCHRATE * c.COINSRATE / 100) AS PREMIUM, --批改保费 'STATDATE' as datetype FROM WEB_LIST_PMAIN c, cd_com_all d, ods_pmain y WHERE c.STATDATE between add_months(trunc(sysdate - 1, 'mm'), -12) and add_months(trunc(sysdate - 1), -12) and c.COMCODE = d.comcode and c.endorseno = y.endorseno(+) and c.CHGPREMIUM != 0 union all select /*+parallel(4) */ e.level2comcode, e.level3comcode, substr(f.RISKCODE, 1, 2) as riskcode, (case when m.newchnltype is null then '00' else m.newchnltype end) newchnltype, (f.PREMIUM * f.EXCHRATE * f.COINSRATE / 100) AS PREMIUM, --原始保费收入 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_CMAINORIGIN f, cd_com_all e, ods_cmain m WHERE f.UNDERWRITEENDDATE between add_months(trunc(sysdate - 1, 'mm'), -12) and add_months(trunc(sysdate - 1), -12) and f.COMCODE = e.comcode and f.policyno = m.policyno(+) UNION ALL select /*+parallel(4) */ h.level2comcode, h.level3comcode, substr(g.RISKCODE, 1, 2) as riskcode, (case when n.newchnltype is null then '00' else n.newchnltype end) newchnltype, (g.CHGPREMIUM * g.EXCHRATE * g.COINSRATE / 100) AS PREMIUM, --批改保费 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_PMAIN g, cd_com_all h, ods_pmain n WHERE g.STATDATE between add_months(trunc(sysdate - 1, 'mm'), -12) and add_months(trunc(sysdate - 1), -12) and g.COMCODE = h.comcode and g.endorseno = n.endorseno(+) and g.CHGPREMIUM != 0) group by level2comcode, level3comcode, riskcode, newchnltype, datetype; --5、去年保费 Execute Immediate 'truncate table jsxs_day_qn1'; insert into jsxs_day_qn1 select /*+parallel(4) */ level2comcode, level3comcode, riskcode, newchnltype, sum(PREMIUM) PREMIUM, datetype from (select /*+parallel(4) */ b.level2comcode, b.level3comcode, substr(a.RISKCODE, 1, 2) as riskcode, (case when x.newchnltype is null then '00' else x.newchnltype end) newchnltype, (a.PREMIUM * a.EXCHRATE * a.COINSRATE / 100) AS PREMIUM, --原始保费收入 'STATDATE' as datetype FROM WEB_LIST_CMAINORIGIN a, cd_com_all b, ods_cmain x WHERE a.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and add_months(trunc(sysdate - 1), -12) and a.COMCODE = b.comcode and a.policyno = x.policyno(+) UNION ALL select /*+parallel(4) */ d.level2comcode, d.level3comcode, substr(c.RISKCODE, 1, 2) as riskcode, (case when y.newchnltype is null then '00' else y.newchnltype end) newchnltype, (c.CHGPREMIUM * c.EXCHRATE * c.COINSRATE / 100) AS PREMIUM, --批改保费 'STATDATE' as datetype FROM WEB_LIST_PMAIN c, cd_com_all d, ods_pmain y WHERE c.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and add_months(trunc(sysdate - 1), -12) and c.COMCODE = d.comcode and c.endorseno = y.endorseno(+) and c.CHGPREMIUM != 0 union all select /*+parallel(4) */ e.level2comcode, e.level3comcode, substr(f.RISKCODE, 1, 2) as riskcode, (case when m.newchnltype is null then '00' else m.newchnltype end) newchnltype, (f.PREMIUM * f.EXCHRATE * f.COINSRATE / 100) AS PREMIUM, --原始保费收入 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_CMAINORIGIN f, cd_com_all e, ods_cmain m WHERE f.UNDERWRITEENDDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and add_months(trunc(sysdate - 1), -12) and f.COMCODE = e.comcode and f.policyno = m.policyno(+) UNION ALL select /*+parallel(4) */ h.level2comcode, h.level3comcode, substr(g.RISKCODE, 1, 2) as riskcode, (case when n.newchnltype is null then '00' else n.newchnltype end) newchnltype, (g.CHGPREMIUM * g.EXCHRATE * g.COINSRATE / 100) AS PREMIUM, --批改保费 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_PMAIN g, cd_com_all h, ods_pmain n WHERE g.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and add_months(trunc(sysdate - 1), -12) and g.COMCODE = h.comcode and g.endorseno = n.endorseno(+) and g.CHGPREMIUM != 0) group by level2comcode, level3comcode, riskcode, newchnltype, datetype; --6、去季度保费 Execute Immediate 'truncate table jsxs_day_qj1 '; insert into jsxs_day_qj1 select /*+parallel(4) */ level2comcode, level3comcode, riskcode, newchnltype, sum(PREMIUM) PREMIUM, datetype from (select /*+parallel(4) */ b.level2comcode, b.level3comcode, substr(a.RISKCODE, 1, 2) as riskcode, (case when x.newchnltype is null then '00' else x.newchnltype end) newchnltype, (a.PREMIUM * a.EXCHRATE * a.COINSRATE / 100) AS PREMIUM, --原始保费收入 'STATDATE' as datetype FROM WEB_LIST_CMAINORIGIN a, cd_com_all b, ods_cmain x WHERE a.STATDATE between add_months(trunc(sysdate - 1, 'q'), -12) and add_months(trunc(sysdate - 1), -12) and a.COMCODE = b.comcode and a.policyno = x.policyno(+) UNION ALL select /*+parallel(4) */ d.level2comcode, d.level3comcode, substr(c.RISKCODE, 1, 2) as riskcode, (case when y.newchnltype is null then '00' else y.newchnltype end) newchnltype, (c.CHGPREMIUM * c.EXCHRATE * c.COINSRATE / 100) AS PREMIUM, --批改保费 'STATDATE' as datetype FROM WEB_LIST_PMAIN c, cd_com_all d, ods_pmain y WHERE c.STATDATE between add_months(trunc(sysdate - 1, 'q'), -12) and add_months(trunc(sysdate - 1), -12) and c.COMCODE = d.comcode and c.endorseno = y.endorseno(+) and c.CHGPREMIUM != 0 union all select /*+parallel(4) */ e.level2comcode, e.level3comcode, substr(f.RISKCODE, 1, 2) as riskcode, (case when m.newchnltype is null then '00' else m.newchnltype end) newchnltype, (f.PREMIUM * f.EXCHRATE * f.COINSRATE / 100) AS PREMIUM, --原始保费收入 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_CMAINORIGIN f, cd_com_all e, ods_cmain m WHERE f.UNDERWRITEENDDATE between add_months(trunc(sysdate - 1, 'q'), -12) and add_months(trunc(sysdate - 1), -12) and f.COMCODE = e.comcode and f.policyno = m.policyno(+) UNION ALL select /*+parallel(4) */ h.level2comcode, h.level3comcode, substr(g.RISKCODE, 1, 2) as riskcode, (case when n.newchnltype is null then '00' else n.newchnltype end) newchnltype, (g.CHGPREMIUM * g.EXCHRATE * g.COINSRATE / 100) AS PREMIUM, --批改保费 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_PMAIN g, cd_com_all h, ods_pmain n WHERE g.STATDATE between add_months(trunc(sysdate - 1, 'q'), -12) and add_months(trunc(sysdate - 1), -12) and g.COMCODE = h.comcode and g.endorseno = n.endorseno(+) and g.CHGPREMIUM != 0) group by level2comcode, level3comcode, riskcode, newchnltype, datetype; --7、当季保费 Execute Immediate 'truncate table jsxs_day_dj1 '; insert into jsxs_day_dj1 select /*+parallel(4) */ level2comcode, level3comcode, riskcode, newchnltype, sum(PREMIUM) PREMIUM, datetype from (select /*+parallel(4) */ b.level2comcode, b.level3comcode, substr(a.RISKCODE, 1, 2) as riskcode, (case when x.newchnltype is null then '00' else x.newchnltype end) newchnltype, (a.PREMIUM * a.EXCHRATE * a.COINSRATE / 100) AS PREMIUM, --原始保费收入 'STATDATE' as datetype FROM WEB_LIST_CMAINORIGIN a, cd_com_all b, ods_cmain x WHERE a.STATDATE between trunc(trunc(sysdate - 1), 'q') and trunc(sysdate - 1) and a.COMCODE = b.comcode and a.policyno = x.policyno(+) UNION ALL select /*+parallel(4) */ d.level2comcode, d.level3comcode, substr(c.RISKCODE, 1, 2) as riskcode, (case when y.newchnltype is null then '00' else y.newchnltype end) newchnltype, (c.CHGPREMIUM * c.EXCHRATE * c.COINSRATE / 100) AS PREMIUM, --批改保费 'STATDATE' as datetype FROM WEB_LIST_PMAIN c, cd_com_all d, ods_pmain y WHERE c.STATDATE between trunc(trunc(sysdate - 1), 'q') and trunc(sysdate - 1) and c.COMCODE = d.comcode and c.endorseno = y.endorseno(+) and c.CHGPREMIUM != 0 union all select /*+parallel(4) */ e.level2comcode, e.level3comcode, substr(f.RISKCODE, 1, 2) as riskcode, (case when m.newchnltype is null then '00' else m.newchnltype end) newchnltype, (f.PREMIUM * f.EXCHRATE * f.COINSRATE / 100) AS PREMIUM, --原始保费收入 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_CMAINORIGIN f, cd_com_all e, ods_cmain m WHERE f.UNDERWRITEENDDATE between trunc(trunc(sysdate - 1), 'q') and trunc(sysdate - 1) and f.COMCODE = e.comcode and f.policyno = m.policyno(+) UNION ALL select /*+parallel(4) */ h.level2comcode, h.level3comcode, substr(g.RISKCODE, 1, 2) as riskcode, (case when n.newchnltype is null then '00' else n.newchnltype end) newchnltype, (g.CHGPREMIUM * g.EXCHRATE * g.COINSRATE / 100) AS PREMIUM, --批改保费 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_PMAIN g, cd_com_all h, ods_pmain n WHERE g.STATDATE between trunc(trunc(sysdate - 1), 'q') and trunc(sysdate - 1) and g.COMCODE = h.comcode and g.endorseno = n.endorseno(+) and g.CHGPREMIUM != 0) group by level2comcode, level3comcode, riskcode, newchnltype, datetype; --8、去年全年保费 Execute Immediate 'truncate table jsxs_day_qqn'; insert into jsxs_day_qqn select /*+parallel(4) */ level2comcode, level3comcode, riskcode, newchnltype, sum(PREMIUM) PREMIUM, datetype from (select /*+parallel(4) */ b.level2comcode, b.level3comcode, substr(a.RISKCODE, 1, 2) as riskcode, (case when x.newchnltype is null then '00' else x.newchnltype end) newchnltype, (a.PREMIUM * a.EXCHRATE * a.COINSRATE / 100) AS PREMIUM, --原始保费收入 'STATDATE' as datetype FROM WEB_LIST_CMAINORIGIN a, cd_com_all b, ods_cmain x WHERE a.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and trunc(sysdate - 1, 'yy') - 1 and a.COMCODE = b.comcode and a.policyno = x.policyno(+) UNION ALL select /*+parallel(4) */ d.level2comcode, d.level3comcode, substr(c.RISKCODE, 1, 2) as riskcode, (case when y.newchnltype is null then '00' else y.newchnltype end) newchnltype, (c.CHGPREMIUM * c.EXCHRATE * c.COINSRATE / 100) AS PREMIUM, --批改保费 'STATDATE' as datetype FROM WEB_LIST_PMAIN c, cd_com_all d, ods_pmain y WHERE c.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and trunc(sysdate - 1, 'yy') - 1 and c.COMCODE = d.comcode and c.endorseno = y.endorseno(+) and c.CHGPREMIUM != 0 union all select /*+parallel(4) */ e.level2comcode, e.level3comcode, substr(f.RISKCODE, 1, 2) as riskcode, (case when m.newchnltype is null then '00' else m.newchnltype end) newchnltype, (f.PREMIUM * f.EXCHRATE * f.COINSRATE / 100) AS PREMIUM, --原始保费收入 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_CMAINORIGIN f, cd_com_all e, ods_cmain m WHERE f.UNDERWRITEENDDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and trunc(sysdate - 1, 'yy') - 1 and f.COMCODE = e.comcode and f.policyno = m.policyno(+) UNION ALL select /*+parallel(4) */ h.level2comcode, h.level3comcode, substr(g.RISKCODE, 1, 2) as riskcode, (case when n.newchnltype is null then '00' else n.newchnltype end) newchnltype, (g.CHGPREMIUM * g.EXCHRATE * g.COINSRATE / 100) AS PREMIUM, --批改保费 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_PMAIN g, cd_com_all h, ods_pmain n WHERE g.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -12) and trunc(sysdate - 1, 'yy') - 1 and g.COMCODE = h.comcode and g.endorseno = n.endorseno(+) and g.CHGPREMIUM != 0) group by level2comcode, level3comcode, riskcode, newchnltype, datetype; --9、前年全年保费 Execute Immediate 'truncate table jsxs_day_qiannianquan'; insert into jsxs_day_qiannianquan select /*+parallel(4) */ level2comcode, level3comcode, riskcode, newchnltype, sum(PREMIUM) PREMIUM, datetype from (select /*+parallel(4) */ b.level2comcode, b.level3comcode, substr(a.RISKCODE, 1, 2) as riskcode, (case when x.newchnltype is null then '00' else x.newchnltype end) newchnltype, (a.PREMIUM * a.EXCHRATE * a.COINSRATE / 100) AS PREMIUM, --原始保费收入 'STATDATE' as datetype FROM WEB_LIST_CMAINORIGIN a, cd_com_all b, ods_cmain x WHERE a.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -24) and add_months(trunc(sysdate - 1, 'yy'), -12) - 1 and a.COMCODE = b.comcode and a.policyno = x.policyno(+) UNION ALL select /*+parallel(4) */ d.level2comcode, d.level3comcode, substr(c.RISKCODE, 1, 2) as riskcode, (case when y.newchnltype is null then '00' else y.newchnltype end) newchnltype, (c.CHGPREMIUM * c.EXCHRATE * c.COINSRATE / 100) AS PREMIUM, --批改保费 'STATDATE' as datetype FROM WEB_LIST_PMAIN c, cd_com_all d, ods_pmain y WHERE c.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -24) and add_months(trunc(sysdate - 1, 'yy'), -12) - 1 and c.COMCODE = d.comcode and c.endorseno = y.endorseno(+) and c.CHGPREMIUM != 0 union all select /*+parallel(4) */ e.level2comcode, e.level3comcode, substr(f.RISKCODE, 1, 2) as riskcode, (case when m.newchnltype is null then '00' else m.newchnltype end) newchnltype, (f.PREMIUM * f.EXCHRATE * f.COINSRATE / 100) AS PREMIUM, --原始保费收入 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_CMAINORIGIN f, cd_com_all e, ods_cmain m WHERE f.UNDERWRITEENDDATE between add_months(trunc(sysdate - 1, 'yy'), -24) and add_months(trunc(sysdate - 1, 'yy'), -12) - 1 and f.COMCODE = e.comcode and f.policyno = m.policyno(+) UNION ALL select /*+parallel(4) */ h.level2comcode, h.level3comcode, substr(g.RISKCODE, 1, 2) as riskcode, (case when n.newchnltype is null then '00' else n.newchnltype end) newchnltype, (g.CHGPREMIUM * g.EXCHRATE * g.COINSRATE / 100) AS PREMIUM, --批改保费 'UNDERWRITEENDDATE' as datetype FROM WEB_LIST_PMAIN g, cd_com_all h, ods_pmain n WHERE g.STATDATE between add_months(trunc(sysdate - 1, 'yy'), -24) and add_months(trunc(sysdate - 1, 'yy'), -12) - 1 and g.COMCODE = h.comcode and g.endorseno = n.endorseno(+) and g.CHGPREMIUM != 0) group by level2comcode, level3comcode, riskcode, newchnltype, datetype;】改为高斯DB
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值