使用union

时间:2018-04-10 17:34:40

标签: sql oracle peoplesoft

我在下面的两个查询中做了联盟,但得到了错误: ORA-00932:不一致的数据类型:预期 - 获得CLOB

SQL看起来像这样:

SELECT A.EMPLID, A.NAME, A.ADM_APPL_NBR, A.ADMIN_FUNCTION, A.STDNT_CAR_NBR, 
A.ACAD_CAREER, A.APPL_PROG_NBR, A.ADMIT_TERM, A.CHECKLIST_CD, A.DESCRSHORT, 
A.CHECKLIST_STATUS, TO_CHAR(A.STATUS_DT,'YYYY-MM-DD'), 
TO_CHAR(A.DUE_DT,'YYYY-MM-DD'), A.COMM_COMMENTS, A.SEQ_3C, A.CHKLST_ITEM_CD, 
A.DESCR, A.ITEM_STATUS, TO_CHAR(A.UM_STATUS_DT_CL,'YYYY-MM-DD'), 
TO_CHAR(A.UM_DUE_DT_CL,'YYYY-MM-DD'), A.RESPONSIBLE_ID 
FROM PS_UM_7902_VW2 A 
WHERE ( 1 = 1 AND EMPLID LIKE DECODE (:1, '', '%', :1) 
AND ADM_APPL_NBR LIKE DECODE(:2, '', '%', :2) 
AND CHECKLIST_CD LIKE DECODE(:3, '', '%', :3) 
 AND A.CHECKLIST_STATUS = :4 
 OR '' = :4 
 AND A.CHECKLIST_STATUS = 'I' 
 OR ( A.CHECKLIST_STATUS = 'C' 
 AND SYSDATE BETWEEN A.TERM_BEGIN_DT AND A.TERM_END_DT) 
 AND ( A.ADMIT_TERM = A.STRM 
 AND SYSDATE BETWEEN A.TERM_BEGIN_DT AND A.TERM_END_DT)) 
 UNION 
 SELECT B.EMPLID, B.NAME, B.ADM_APPL_NBR, B.ADMIN_FUNCTION, B.STDNT_CAR_NBR, 
 B.ACAD_CAREER, B.APPL_PROG_NBR, B.ADMIT_TERM, B.CHECKLIST_CD, B.DESCRSHORT, 
 B.CHECKLIST_STATUS, TO_CHAR(B.STATUS_DT,'YYYY-MM-DD'), 
 TO_CHAR(B.DUE_DT,'YYYY-MM-DD'), B.COMM_COMMENTS, B.SEQ_3C, 
 B.CHKLST_ITEM_CD, B.DESCR, B.ITEM_STATUS, TO_CHAR(B.UM_STATUS_DT_CL,'YYYY- 
 MM-DD'), TO_CHAR(B.UM_DUE_DT_CL,'YYYY-MM-DD'), B.RESPONSIBLE_ID 
 FROM PS_UM_7902_VW2 B 
 WHERE ( B.EMPLID = :1 
 AND 1 = 1 and ADM_APPL_NBR like DECODE(:2, '', '%', :2)
 and CHECKLIST_CD like DECODE(:3, '', '%', :3) 
 AND B.CHECKLIST_STATUS = 'I' 
 OR ( B.CHECKLIST_STATUS = 'C' 
 AND SYSDATE BETWEEN B.TERM_BEGIN_DT AND B.TERM_END_DT) 
 AND B.ADMIT_TERM = B.STRM 
 AND SYSDATE BETWEEN B.TERM_BEGIN_DT AND B.TERM_END_DT);

请帮帮我们。

1 个答案:

答案 0 :(得分:2)

A.COMM_COMMENTSB.COMM_COMMENTS是CLOB。你不能联合CLOB。 另一种方法是做TO_CHAR(A.COMM_COMMENTS)TO_CHAR(B.COMM_COMMENTS),然后就可以了。