-----------------------------------------------总结、提高------------------------------------------------------
FineReport帮助文档
=CONCATENATE (LEFT($dtFromDate, 4), "年", $cmbGroup, "组AOI缺陷分类表")
-- SQL中是CONCAT,同 ||
SELECT
COUNT(CODE)QTY, ABNORMAL_DESC
FROM IMP_PROD_ABNORMAL
WHERE SER='AOI_Abnor'
AND CLASSIFY='${cmbGroup}'
AND TO_CHAR(OCCUR_DATE,'YYYYMMDD') BETWEEN TO_CHAR(CASE WHEN TO_CHAR(TO_DATE(REPLACE('${dtEndDate}','-',''),'yyyymmdd')-1,'D') < '4'
THEN TO_DATE(REPLACE('${dtEndDate}','-',''),'yyyymmdd')-7+4-TO_CHAR(TO_DATE(REPLACE('${dtEndDate}','-',''),'yyyymmdd')-1,'D')
WHEN TO_CHAR(TO_DATE(REPLACE('${dtEndDate}','-',''),'yyyymmdd')-1,'D') >= '4'
THEN TO_DATE(REPLACE('${dtEndDate}','-',''),'yyyymmdd')-TO_CHAR(TO_DATE(REPLACE('${dtEndDate}','-',''),'yyyymmdd')-1,'D')+4 END,'YYYYMMDD')
AND REPLACE('${dtEndDate}','-','')
--${IF(LEN(cmbWeek) == 0,"","AND 'WK'||TO_CHAR(OCCUR_DATE+4,'IW') IN ('" + cmbWeek + "')")}
GROUP BY ABNORMAL_DESC
其中,REPLACE函数的用法:
使用的函数为replace()
含义为:替换字符串
replace(原字段,“原字段旧内容“,“原字段新内容“,)
REGEXP_REPLACE用法 (正则表达式)
TO_NUMBER(REGEXP_REPLACE(TYPENAME,’[^0-9]’)) FLAG
语句:
update sys_frmattachmentdb set filefullname = replace(filefullname,'历城区,'北京区‘)
NVL2(MACHINE_TIME,(MACHINE_TIME-RELEASE_TIME)*24,(sysdate-RELEASE_TIME)*24) RELEASE_DURATION
WHERE 1=1
AND MATERIALS_TYPE = '${cmbMATERIALS_TYPE}'
${if(len(cmbPRD_SPECNAME)==0," " ," AND PRD_SPECNAME IN ('"+cmbPRD_SPECNAME+"')")}
${if(len(cmbLOTNAME)==0," " ," AND LOTNAME IN ('"+cmbLOTNAME+"')")}
AND RELEASE_TIME BETWEEN DATE '${dtReleaseStart}' AND DATE '${dtReleaseEnd}'
${IF(LEN(ST)*LEN(ET)==0,"","and MACHINE_TIME between to_date('"+ST+"','YYYY-MM-DD') and to_date('"+ET+"','YYYY-MM-DD')")}
${if(chkDura == true,"AND NVL2(MACHINE_TIME,(sysdate-RELEASE_TIME),(MACHINE_TIME-RELEASE_TIME))>24","")}
${if(len(cmbEVENT_USER1)==0," " ," AND EVENT_USER1 IN ('"+cmbEVENT_USER1+"')")}
${if(len(cmbEVENT_USER2)==0," " ," AND EVENT_USER2 IN ('"+cmbEVENT_USER2+"')")}
TO_CHAR(ADD_MONTHS(SYSDATE-1,-3),'YYYYMM')
注意ADD_MONTHS的用法:
add_months 函数主要是对日期函数进行操作
add_months 有两个参数,第一个参数是日期,第二个参数是对日期进行加减的数字(以月为单位的
TRUNC用法:
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'),
to_char(trunc(sysdate), 'yyyy-mm-dd hh24:mi:ss')from dual t;--sysdate和trunc(sysdate)是不一样的 sysdate在当天的零时零分零秒等于trunc(sysdate)
select trunc(sysdate, 'dd'), trunc(sysdate) from dual t; --今天 20140703 零时零分零秒
select to_char(trunc(sysdate, 'dd'), 'yyyy/mm/dd hh24:mi:ss'),
to_char(trunc(sysdate), 'yyyy/mm/dd hh24:mi:ss')
from dual;
select trunc(sysdate-to_date('20140709 23:12:12','yyyy/mm/dd hh24:mi:ss')) from dual t;--两个日期相差的天数
select trunc(sysdate-1) from dual t;--昨天
select trunc(sysdate+1) from dual t;--明天
select trunc(sysdate, 'yy') from dual;--当年第一天
select trunc(sysdate, 'year') from dual;--当年第一天
select trunc(sysdate, 'yyyy') from dual;--当年第一天
select trunc(sysdate, 'q') from dual;--当前时间所在的季度的第一天
select trunc(sysdate, 'mm') from dual;--当月第一天
select trunc(sysdate, 'month') from dual;--当月第一天
select trunc(sysdate, 'd') from dual;--返回本周的第一天(周日为第一天)
select trunc(sysdate,'day') from dual;--返回本周的第一天(周日为第一天)
select trunc(sysdate, 'iw') from dual;--本周第二天(周日为第一天)
select trunc(sysdate, 'hh') from dual; --当前时间,精确到小时
select trunc(sysdate, 'hh24') from dual;--当前时间。精确到小时
select trunc(sysdate, 'mi') from dual;--当前时间。精确到分钟 没有精确到秒的精度
改天整理
AND TO_CHAR (OCCUR_DATE,'YYYYMM')=' ${dtBL_Year}' || '${dtBL_Mon}'
– 年、月分开做筛选条件的情况