SELECT
TB_A.this_week_monday
, TB_A.this_week_sunday
, TB_B.IMG_LCL_NM
, TB_B.IMG_NM
, TB_B.IMG_URL
, TB_B.EPS_SEQ
, TB_C.GR_NM
, TB_C.GR_CL_CD
, TB_C.MBR_NO
, CASE WHEN TO_CHAR(SYSDATE, 'DY', 'NLS_DATE_LANGUAGE=AMERICAN') = 'MON' AND TO_CHAR(SYSDATE, 'HH24:MI:SS') BETWEEN '00:00:00' AND '08:59:59'
THEN 'Y' ELSE 'N' END AS GRD_CLT_YN
, CASE WHEN TO_CHAR(SYSDATE, 'DY', 'NLS_DATE_LANGUAGE=AMERICAN') = 'MON' AND TO_CHAR(SYSDATE, 'HH24:MI:SS') BETWEEN '00:00:00' AND '08:59:59'
THEN CASE WHEN (SELECT COUNT(*)
FROM TB_BRND_BNFT
WHERE BNFT_STA_DT >= TRUNC(NEXT_DAY(SYSDATE-7, 'monday')) AND
BNFT_END_DT < TRUNC(NEXT_DAY(SYSDATE, 'monday')+1)
) > 0
THEN 'case 1'
ELSE 'case 2'
END
ELSE 'case 3'
END AS CMMT
FROM ( SELECT
SYSDATE + (1 - TO_CHAR(SYSDATE,'D'))+ 1 AS this_week_monday
, SYSDATE + (1 - TO_CHAR(SYSDATE,'D'))+ 7 AS this_week_sunday
FROM DUAL
)TB_A
, ( SELECT
IMG_LCL_NM
, IMG_NM
, IMG_URL
, B.EPS_SEQ
FROM TB_BRND_MGMT A JOIN TB_BRND_BNFT B ON A.GRP_MCHT_NO = B.GRP_MCHT_NO
WHERE BNFT_STA_DT >= TRUNC(NEXT_DAY(SYSDATE-7, 'monday')) AND
BNFT_END_DT < TRUNC(NEXT_DAY(SYSDATE, 'monday')+1)
) TB_B
, (
SELECT
GR_NM
, TB_MBR_GR.GR_CL_CD
, APLY_STA_DT
, MBR_NO
FROM TB_MBR_GR
LEFT JOIN TB_MBR_GR_SET
ON TB_MBR_GR.GR_CL_CD = TB_MBR_GR_SET.GR_CL_CD
WHERE MBR_NO = '2000000001'
ORDER BY APLY_STA_DT DESC
FETCH FIRST 1 ROWS ONLY
) TB_C
;
错误“文字与格式字符串不匹配”继续发生。'BNFT_STA_DT'和'BNFT_END_DT'是varchar 2类型。我认为sysdate和next_day函数有问题。我不知道在哪里或如何修复它。救命啊!
1条答案
按热度按时间pkbketx91#
您可以使用
TO_DATE
将字符串转换为日期(并且不应将日期存储在VARCHAR2
字段中),并且可以使用TRUNC(SYSDATE, 'IW')
查找当前星期一的午夜。例如,如果日期数据以
YYYY-MM-DD HH24:MI:SS
存储,则: