SELECT * FROM PMS_SHEET ps, PMS_EQUIPMENT pe WHERE ps.EQUIPMENT_TYPE = pe.EQUIPMENT_TYPE AND ps.IS_ACTIVE = 'Y' AND (ps.ORG_RRN = :orgRrn OR ps.ORG_RRN = 0) AND pe.IS_ACTIVE = 'Y' AND (pe.ORG_RRN = :orgRrn OR pe.ORG_RRN = 0) AND ps.CATEGORY = 'DC' AND (ps."TYPE" <> 'SC' OR (ps."TYPE" ='SC' AND EXISTS ( SELECT 1 FROM PMS_SCHEDULE psd WHERE psd.EQUIPMENT_ID = pe.EQUIPMENT_ID AND psd.SHEET_RRN = ps.OBJECT_RRN AND psd.SCHEDULE_TIME BETWEEN '2023/06/01 00:00:00' AND '2023/06/30 23:59:59' ) ) ) 这个sql执行的结果为什么会报错 ORA-01861: 文字与格式字符串不匹配
时间: 2024-03-15 10:44:58 浏览: 72
PMS.rar_ PMS.rar_DMB_PM_PMS_cmmb pms
这个SQL语句中包含了两个日期常量:'2023/06/01 00:00:00'和'2023/06/30 23:59:59'。然而,Oracle数据库中默认的日期格式与这些常量的格式不匹配,因此会报错ORA-01861。
为了解决这个问题,可以将常量中的斜杠替换为短横线,或者使用TO_DATE函数将常量转换为日期类型。例如:
```
SELECT * FROM PMS_SHEET ps, PMS_EQUIPMENT pe
WHERE ps.EQUIPMENT_TYPE = pe.EQUIPMENT_TYPE
AND ps.IS_ACTIVE = 'Y'
AND (ps.ORG_RRN = :orgRrn OR ps.ORG_RRN = 0)
AND pe.IS_ACTIVE = 'Y'
AND (pe.ORG_RRN = :orgRrn OR pe.ORG_RRN = 0)
AND ps.CATEGORY = 'DC'
AND (ps."TYPE" <> 'SC'
OR (ps."TYPE" ='SC'
AND EXISTS (
SELECT 1 FROM PMS_SCHEDULE psd
WHERE psd.EQUIPMENT_ID = pe.EQUIPMENT_ID
AND psd.SHEET_RRN = ps.OBJECT_RRN
AND psd.SCHEDULE_TIME BETWEEN TO_DATE('2023-06-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2023-06-30 23:59:59', 'YYYY-MM-DD HH24:MI:SS')
)
)
);
```
或者:
```
SELECT * FROM PMS_SHEET ps, PMS_EQUIPMENT pe
WHERE ps.EQUIPMENT_TYPE = pe.EQUIPMENT_TYPE
AND ps.IS_ACTIVE = 'Y'
AND (ps.ORG_RRN = :orgRrn OR ps.ORG_RRN = 0)
AND pe.IS_ACTIVE = 'Y'
AND (pe.ORG_RRN = :orgRrn OR pe.ORG_RRN = 0)
AND ps.CATEGORY = 'DC'
AND (ps."TYPE" <> 'SC'
OR (ps."TYPE" ='SC'
AND EXISTS (
SELECT 1 FROM PMS_SCHEDULE psd
WHERE psd.EQUIPMENT_ID = pe.EQUIPMENT_ID
AND psd.SHEET_RRN = ps.OBJECT_RRN
AND psd.SCHEDULE_TIME BETWEEN '2023-06-01 00:00:00' AND '2023-06-30 23:59:59'
)
)
);
```
阅读全文