我的代码出现ORA-00918错误,我找不到问题...以下代码给了我这个错误。
ORA-00918:列定义不明确
有人可以给我一些建议吗?谢谢
SELECT * FROM (
SELECT * FROM (
SELECT ROWNUM AS RNUM, A.XML_MSG_ID, A.LOGIN_ID, A.ORIGINATOR, A.RECIPIENT, A.ERROR_CODE, B.DOC_NO, B.DOC_NAME, B.ERROR_MSG
FROM XML_MANAGE_TBL A, XML_REFERENCE_TBL B
WHERE A.XML_MGS_ID = B.XML_MSG_ID
AND A.ERROR_CODE <> '00000000'
AND A.XML_MSG_ID >= '20190528' AND (SUBSTR(A.XML_MSG_ID, 1, 8)) <= '20190604' ) C, EBILL_USER D WHERE D.COMP_NUM = '1258169573' AND C.ORIGINATOR = D.ORIGINATOR )
WHERE RNUM BETWEEN CASE WHEN (1-1) != 0 THEN ((1-1)*50)+1 ELSE (1-1)*50 END
AND 1*50;
答案 0 :(得分:1)
问题很可能是在第二个子查询select *
SELECT * FROM (
... subquery C ...
) C, EBILL_USER D WHERE ... AND C.ORIGINATOR = D.ORIGINATOR
表D
包含与子查询C
相同的列,请确保ORIGINATOR
列
只需将第二个查询更改为SELECT C.*
,然后仅从D
添加所需的列即可。
一般方法如何解决ORA-00918
的问题是从最里面的子查询中运行查询,并检查返回的列名是否唯一。
您的情况请先尝试,应该没问题
SELECT ROWNUM AS RNUM, A.XML_MSG_ID, A.LOGIN_ID, A.ORIGINATOR, A.RECIPIENT, A.ERROR_CODE, B.DOC_NO, B.DOC_NAME, B.ERROR_MSG
FROM XML_MANAGE_TBL A, XML_REFERENCE_TBL B
WHERE A.XML_MGS_ID = B.XML_MSG_ID
AND A.ERROR_CODE <> '00000000'
AND A.XML_MSG_ID >= '20190528' AND (SUBSTR(A.XML_MSG_ID, 1, 8)) <= '20190604'
比运行第二个最里面的子查询
SELECT * FROM (
SELECT ROWNUM AS RNUM, A.XML_MSG_ID, A.LOGIN_ID, A.ORIGINATOR, A.RECIPIENT, A.ERROR_CODE, B.DOC_NO, B.DOC_NAME, B.ERROR_MSG
FROM XML_MANAGE_TBL A, XML_REFERENCE_TBL B
WHERE A.XML_MGS_ID = B.XML_MSG_ID
AND A.ERROR_CODE <> '00000000'
AND A.XML_MSG_ID >= '20190528' AND (SUBSTR(A.XML_MSG_ID, 1, 8)) <= '20190604' ) C, EBILL_USER D WHERE D.COMP_NUM = '1258169573' AND C.ORIGINATOR = D.ORIGINATOR
在您的IDE(例如SQL Developer)中,您将看到一个或多个带有后缀_1
的列,这是重复列的标志,必须排除(对于Equijoin谓词中的列)或重命名。 >
答案 1 :(得分:1)
您只需要删除最外面的查询,并在where子句中使用C.RNUM而不是RNUM。尝试以下代码:
SELECT * FROM (
SELECT ROWNUM AS RNUM, A.XML_MSG_ID, A.LOGIN_ID, A.ORIGINATOR, A.RECIPIENT, A.ERROR_CODE, B.DOC_NO, B.DOC_NAME, B.ERROR_MSG
FROM XML_MANAGE_TBL A, XML_REFERENCE_TBL B
WHERE A.XML_MGS_ID = B.XML_MSG_ID
AND A.ERROR_CODE <> '00000000'
AND A.XML_MSG_ID >= '20190528' AND (SUBSTR(A.XML_MSG_ID, 1, 8)) <= '20190604' ) C, EBILL_USER D WHERE D.COMP_NUM = '1258169573' AND C.ORIGINATOR = D.ORIGINATOR
and (C.RNUM BETWEEN CASE WHEN (1-1) != 0 THEN ((1-1)*50)+1 ELSE (1-1)*50 END AND 1*50);