timpoynter
asked on
ORA-00918: column ambiguously defined
Hi
Why am I getting the following error when all columns are prefixed with table names???
See Code for view definition
ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Error at Line: 32 Column: 18
Why am I getting the following error when all columns are prefixed with table names???
See Code for view definition
ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Error at Line: 32 Column: 18
CREATE OR REPLACE FORCE VIEW xxkp_ctp_det_gr_v (AU_SID
,AU_ID
,AU_NAME
,ACTIVITY_ID
,ACTIVITY_NAME
,WORKGROUP_ID
,WORKGROUP_NAME
,USER_ID
,USERNAME
,FIRST_NAME
,LAST_NAME
,SUBJECT_COMPLETE
,POSTASSESS_COMPLETE
,BOTH_COMPLETE
,SCORE
,POSTASSESS_REQUIRED_SCORE
,PASSED
,XFAILED
,NOT_STARTED
,SUBJECT_IN_PROGRESS
,POSTASSESS_IN_PROGRESS
)
AS
SELECT XXKP_CTP_DET_V.AU_SID
, XXKP_CTP_DET_V.AU_ID
, XXKP_CTP_DET_V.AU_NAME
, XXKP_CTP_DET_V.ACTIVITY_NAME
, XXKP_CTP_DET_V.WORKGROUP_ID
, XXKP_CTP_DET_V.WORKGROUP_NAME
, XXKP_CTP_DET_V.USER_ID
, XXKP_CTP_DET_V.USERNAME
, XXKP_CTP_DET_V.FIRST_NAME
, XXKP_CTP_DET_V.LAST_NAME
, COUNT(DISTINCT(XXKP_CTP_DET_V.ASSESS_RESULT_ID)) AS NO_OF_POSTASSESS_ATTEMPTS
, CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.SUBJECT_COMPLETE = 1 THEN 1 ELSE 0 END) > 0
THEN 1 ELSE 0 END AS SUBJECT_COMPLETE
, CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.POSTASSESS_COMPLETE = 1 THEN 1 ELSE 0 END) > 0
THEN 1 ELSE 0 END AS POSTASSESS_COMPLETE
, CASE WHEN (CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.SUBJECT_COMPLETE = 1 THEN 1 ELSE 0 END) > 0
THEN 1 ELSE 0 END) = 1 AND
(CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.POSTASSESS_COMPLETE = 1 THEN 1 ELSE 0 END) > 0
THEN 1 ELSE 0 END) = 1 THEN 1 ELSE 0 END AS BOTH_COMPLETE
, CASE WHEN MAX(XXKP_CTP_DET_V.SCORE * 100) IS NULL THEN 0 ELSE MAX(XXKP_CTP_DET_V.SCORE * 100) END AS SCORE
, CASE WHEN MAX(XXKP_CTP_DET_V.POSTASSESS_REQUIRED_SCORE * 100) IS NULL
THEN 0 ELSE MAX(XXKP_CTP_DET_V.POSTASSESS_REQUIRED_SCORE * 100) END AS POSTASSESS_REQUIRED_SCORE
, CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.PASSED = 1 THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END AS PASSED
, CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.PASSED = 1 THEN 1 ELSE 0 END) = 0
AND SUM(CASE WHEN XXKP_CTP_DET_V.XFAILED = 1 THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END AS XFAILED
, CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.SUBJECT_COMPLETE_PERCENTAGE IS NULL THEN 0 ELSE 1 END) = 0 AND
(SUM(CASE WHEN XXKP_CTP_DET_V.SCORE IS NULL THEN 0 ELSE 1 END) = 0) THEN 1 ELSE 0 END AS NOT_STARTED
, CASE WHEN SUM(XXKP_CTP_DET_V.SUBJECT_IN_PROGRESS) > 0 AND
(CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.SUBJECT_COMPLETE = 1 THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END) <> 1
THEN 1 ELSE 0 END AS SUBJECT_IN_PROGRESS
, CASE WHEN SUM(XXKP_CTP_DET_V.POSTASSESS_IN_PROGRESS) > 0 AND
(CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.POSTASSESS_COMPLETE = 1 THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END) <> 1 THEN 1 ELSE 0 END AS POSTASSESS_IN_PROGRESS
FROM XXKP_CTP_DET_V
GROUP BY XXKP_CTP_DET_V.AU_SID
, XXKP_CTP_DET_V.AU_ID
, XXKP_CTP_DET_V.AU_NAME
, XXKP_CTP_DET_V.ACTIVITY_NAME
, XXKP_CTP_DET_V.WORKGROUP_ID
, XXKP_CTP_DET_V.WORKGROUP_NAME
, XXKP_CTP_DET_V.USER_ID
, XXKP_CTP_DET_V.USERNAME
, XXKP_CTP_DET_V.FIRST_NAME
, XXKP_CTP_DET_V.LAST_NAME
/
EXIT
prefix table name to all the columns referred in select statement
ASKER
Hi
Thanks for the responses, but I am only querying one view and every column is prefixed (I think) please have a look at the code
Thanks for the responses, but I am only querying one view and every column is prefixed (I think) please have a look at the code
try to run select statement only and see if it gives error.. if so, try to removing few parts of the query to debug the actual problem in it
ASKER
I have its this element it doesn't like
CASE WHEN SUM(XXKP_CTP_DET_V.POSTASS ESS_IN_PRO GRESS) > 0 AND
(CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.POSTASSESS_ COMPLETE = 1 THEN 1 ELSE 0 END) > 0 THEN 1 ELSE 0 END) <> 1 THEN 1 ELSE 0 END AS POSTASSESS_IN_PROGRESS
As you can see everything is prefixed!
Any ideas???
CASE WHEN SUM(XXKP_CTP_DET_V.POSTASS
(CASE WHEN SUM(CASE WHEN XXKP_CTP_DET_V.POSTASSESS_
As you can see everything is prefixed!
Any ideas???
You say you are querying a view. Is it possible the view itself is causing the problem i.e. the view retrieves from multiple tables but isn't correctly prefixing the columns?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
neeraj523
Thank you so much, when I did a select * I could see that there were an invalid number of columns of the view I was selecting from, fixed that and now the query works
Thanks
Thank you so much, when I did a select * I could see that there were an invalid number of columns of the view I was selecting from, fixed that and now the query works
Thanks
great to know that you were able to resolve the issue..
all the best
all the best
Introduce a table alias and then qualify the column name with the alias. This way you tell Oracle exactly which table the column should be taken from
e.g.
select t1.col,
t2.col
from table1 t1,
table 2 t2