我在下面的pl / sql查询中得到ora-12704错误 - 有人可以帮我指出正确的解决方案吗?
SELECT "STAT"."ORD"."SAMPLEID",
MAX(CASE WHEN "STAT"."ORDANAEL"."MC"='QAERS' THEN "STAT"."ORDANAEL"."RES_TXT" ELSE
'' END) AS ERSID,
"STAT"."ORDMCSTP_V"."SEQNB", "STAT"."ORD"."ORDPATNAME",
"STAT"."ORD"."ORDPATBIRTHDT", "STAT"."ORD"."CORORDNB", "STAT"."ORD"."PROJNB",
Max(CASE WHEN "STAT"."ORDANAEL"."MC"='AMMOL' THEN 'AMMOL'
WHEN "STAT"."ORDANAEL"."MC"='AMMOLR' THEN 'AMMOLR' ELSE '' END) AS TEST,
Max(CASE WHEN "STAT"."ORDANAEL"."MC"='AMMOL' THEN "STAT"."ORDRESMCEL"."MC_RES"
WHEN "STAT"."ORDANAEL"."MC"='AMMOLR' THEN "STAT"."ORDRESMCEL"."MC_RES" ELSE ''
END) AS MC_RES,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMIMI' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS IMI,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMIMP' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS IMP,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMNDM' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS NDM,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMOX48' THEN
"STAT"."ORDMCSTPEL"."RES" ELSE '' END) AS OXA48,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMSPM' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS SPM,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMVIM' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS VIM,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMDIM' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS DIM,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMKPC' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS KPC,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMGES' THEN"STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS GES,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMSME' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS SME,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMFRI1' THEN
"STAT"."ORDMCSTPEL"."RES" ELSE '' END) AS FRI1,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMSIM' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS SIM,
Max( CASE WHEN "STAT"."ORDMCSTP_V"."STEPMC"='AMGIM' THEN "STAT"."ORDMCSTPEL"."RES"
ELSE '' END) AS GIM,
Max( CASE WHEN "STAT"."ORDANAEL"."MC"='AMMOL' THEN "STAT"."ORDANAEL"."VALMED" ELSE
'' END) AS VALMED_AMMOL,
Max( CASE WHEN "STAT"."ORDANAEL"."MC"='AMMOL' AND
"STAT"."ORDANAEL_D"."DFIELD"='RR' THEN "STAT"."ORDANAEL_D"."DVALUE" ELSE '' END)
AS RPT_DT_AMMOL,
"STAT"."ORDANAEL"."RES_ST"
FROM (("STAT"."ORDMCSTPEL" INNER JOIN ("STAT"."ORDMCSTP_V" INNER JOIN
("STAT"."ORD" INNER JOIN "STAT"."ORDANAEL" ON ("STAT"."ORD"."LID" =
"STAT"."ORDANAEL"."LID") AND ("STAT"."ORD"."LPERIOD" =
"STAT"."ORDANAEL"."LPERIOD") AND ("STAT"."ORD"."ORDNB" =
"STAT"."ORDANAEL"."ORDNB")) ON ("STAT"."ORDMCSTP_V"."LID" = "STAT"."ORD"."LID")
AND ("STAT"."ORDMCSTP_V"."LPERIOD" = "STAT"."ORD"."LPERIOD") AND
("STAT"."ORDMCSTP_V"."ORDNB" = "STAT"."ORD"."ORDNB")) ON ("STAT"."ORDMCSTPEL"."BC"
= "STAT"."ORDMCSTP_V"."BC") AND ("STAT"."ORDMCSTPEL"."CURRENT_STEPNB" =
"STAT"."ORDMCSTP_V"."CURRENT_STEPNB")) INNER JOIN "STAT"."ORDANAEL_D" ON
("STAT"."ORDANAEL"."NBINT" = "STAT"."ORDANAEL_D"."DNBINT") AND
("STAT"."ORDANAEL"."SPSEQ" = "STAT"."ORDANAEL_D"."DSPSEQ") AND
("STAT"."ORDANAEL"."ORDNB" = "STAT"."ORDANAEL_D"."DORDNB") AND
("STAT"."ORDANAEL"."LPERIOD" = "STAT"."ORDANAEL_D"."DLPERIOD") AND
("STAT"."ORDANAEL"."LID" = "STAT"."ORDANAEL_D"."DLID")) INNER JOIN
"STAT"."ORDRESMCEL" ON ("STAT"."ORDMCSTP_V"."SEQNB" = "STAT"."ORDRESMCEL"."SEQNB")
AND ("STAT"."ORDANAEL"."ORDNB" = "STAT"."ORDRESMCEL"."ORDNB") AND
("STAT"."ORDANAEL"."LPERIOD" = "STAT"."ORDRESMCEL"."LPERIOD") AND
("STAT"."ORDANAEL"."LID" = "STAT"."ORDRESMCEL"."LID")
WHERE (("STAT"."ORD"."LID")='H1')
AND (("STAT"."ORD"."LPERIOD")>'5200')
AND (("STAT"."ORD"."PROJNB")='ACPOERS')
GROUP BY "STAT"."ORD"."SAMPLEID", "STAT"."ORDMCSTP_V"."SEQNB",
"STAT"."ORD"."ORDPATNAME", "STAT"."ORD"."ORDPATBIRTHDT", "STAT"."ORD"."CORORDNB",
"STAT"."ORD"."PROJNB", "STAT"."ORDANAEL"."RES_ST"
HAVING ((("STAT"."ORDMCSTP_V"."SEQNB") Is Not Null) AND (("STAT"."ORD"."PROJNB")
='ACPOERS') AND (("STAT"."ORDANAEL"."RES_ST")>'4'))
答案 0 :(得分:0)
我认为这是因为查询中的文字和一些NVARCHAR2列的使用 在比较中。而且这部分还有一个错误
Max( CASE WHEN STAT.ORDMCSTP_V.STEPMC=n'AMGES' THENSTAT.ORDMCSTPEL.RES ELSE n'' END) AS GES,
THENSTAT需要一个空格
请检查这种类型的查询,然后根据女巫列为NVARCHAR2将与“ ABC”相同的一些文字更改为n'ABC'。
如果所有列都是NVARCHAR2,则查询必须是这样的:
SELECT STAT.ORD.SAMPLEID,
MAX(CASE
WHEN STAT.ORDANAEL.MC = n'QAERS' THEN
STAT.ORDANAEL.RES_TXT
ELSE
n''
END) AS ERSID,
STAT.ORDMCSTP_V.SEQNB,
STAT.ORD.ORDPATNAME,
STAT.ORD.ORDPATBIRTHDT,
STAT.ORD.CORORDNB,
STAT.ORD.PROJNB,
Max(CASE
WHEN STAT.ORDANAEL.MC = n'AMMOL' THEN
n'AMMOL'
WHEN STAT.ORDANAEL.MC = n'AMMOLR' THEN
n'AMMOLR'
ELSE
n''
END) AS TEST,
Max(CASE
WHEN STAT.ORDANAEL.MC = n'AMMOL' THEN
STAT.ORDRESMCEL.MC_RES
WHEN STAT.ORDANAEL.MC = n'AMMOLR' THEN
STAT.ORDRESMCEL.MC_RES
ELSE
n''
END) AS MC_RES,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMIMI' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS IMI,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMIMP' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS IMP,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMNDM' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS NDM,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMOX48' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS OXA48,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMSPM' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS SPM,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMVIM' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS VIM,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMDIM' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS DIM,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMKPC' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS KPC,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMGES' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS GES,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMSME' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS SME,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMFRI1' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS FRI1,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMSIM' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS SIM,
Max(CASE
WHEN STAT.ORDMCSTP_V.STEPMC = n'AMGIM' THEN
STAT.ORDMCSTPEL.RES
ELSE
n''
END) AS GIM,
Max(CASE
WHEN STAT.ORDANAEL.MC = n'AMMOL' THEN
STAT.ORDANAEL.VALMED
ELSE
n''
END) AS VALMED_AMMOL,
Max(CASE
WHEN STAT.ORDANAEL.MC = n'AMMOL' AND STAT.ORDANAEL_D.DFIELD = n'RR' THEN
STAT.ORDANAEL_D.DVALUE
ELSE
n''
END) RPT_DT_AMMOL,
STAT.ORDANAEL.RES_ST
FROM STAT.ORDMCSTPEL,
STAT.ORDMCSTP_V,
STAT.ORD,
STAT.ORDANAEL,
STAT.ORDANAEL_D,
STAT.ORDRESMCEL
WHERE (STAT.ORD.LID = STAT.ORDANAEL.LID)
AND (STAT.ORD.LPERIOD = STAT.ORDANAEL.LPERIOD)
AND (STAT.ORD.ORDNB = STAT.ORDANAEL.ORDNB)
AND (STAT.ORDMCSTP_V.LID = STAT.ORD.LID)
AND (STAT.ORDMCSTP_V.LPERIOD = STAT.ORD.LPERIOD)
AND (STAT.ORDMCSTP_V.ORDNB = STAT.ORD.ORDNB)
AND (STAT.ORDMCSTPEL.BC = STAT.ORDMCSTP_V.BC)
AND (STAT.ORDMCSTPEL.CURRENT_STEPNB = STAT.ORDMCSTP_V.CURRENT_STEPNB)
AND (STAT.ORDANAEL.NBINT = STAT.ORDANAEL_D.DNBINT)
AND (STAT.ORDANAEL.SPSEQ = STAT.ORDANAEL_D.DSPSEQ)
AND (STAT.ORDANAEL.ORDNB = STAT.ORDANAEL_D.DORDNB)
AND (STAT.ORDANAEL.LPERIOD = STAT.ORDANAEL_D.DLPERIOD)
AND (STAT.ORDANAEL.LID = STAT.ORDANAEL_D.DLID)
AND (STAT.ORDMCSTP_V.SEQNB = STAT.ORDRESMCEL.SEQNB)
AND (STAT.ORDANAEL.ORDNB = STAT.ORDRESMCEL.ORDNB)
AND (STAT.ORDANAEL.LPERIOD = STAT.ORDRESMCEL.LPERIOD)
AND (STAT.ORDANAEL.LID = STAT.ORDRESMCEL.LID)
AND ((STAT.ORD.LID) = n'H1')
AND ((STAT.ORD.LPERIOD) > '5200')
AND ((STAT.ORD.PROJNB) = n'ACPOERS')
GROUP BY STAT.ORD.SAMPLEID,
STAT.ORDMCSTP_V.SEQNB,
STAT.ORD.ORDPATNAME,
STAT.ORD.ORDPATBIRTHDT,
STAT.ORD.CORORDNB,
STAT.ORD.PROJNB,
STAT.ORDANAEL.RES_ST
HAVING(((STAT.ORDMCSTP_V.SEQNB) Is Not Null) AND ((STAT.ORD.PROJNB) = n'ACPOERS') AND ((STAT.ORDANAEL.RES_ST) > '4'))