gshanmugam
asked on
ORA-00979 when creating a view with a correlated subquery
When I run this SQL statement I get an ORA-00979: not a GROUP by expression:
CREATE VIEW PS_CG_INCDATRDY_VW (SETID, YC_DATA_CD, YC_DATA_CD_TYP, ASOF_DT, YC_MKT_ISSUE_CD, CG_X_VALUE, CG_Y_VALUE, YC_PRICE, YC_COUPON) AS SELECT A.SETID , A.YC_DATA_CD , 'I' YC_DATA_CD_TYP , C.ASOF_DT ASOF_DT , ' ' YC_MKT_ISSUE_CD , 0 CG_X_VALUE , 0 CG_Y_VALUE , 0 YC_PRICE , 0 YC_COUPON FROM PS_YC_DATADEF_TBL A , PS_YC_TERM_STRUCT B , PS_YC_RATE_TBL C , PS_CG_MKTCURVES_VW D WHERE A.SETID = B.SETID AND A.YC_DATA_CD = B.YC_DATA_CD AND A.YC_DATA_CD_TYP = 'M' AND B.YC_MKT_ISSUE_CD = C.YC_MKT_ISSUE_CD AND A.SETID = D.SETID AND A.YC_DATA_CD = D.YC_DATA_CD AND C.ASOF_DT = D.ASOF_DT AND D.YC_COUNT < ( SELECT COUNT(*) FROM PS_YC_TERM_STRUCT E WHERE B.SETID = E.SETID AND B.YC_DATA_CD = E.YC_DATA_CD ) GROUP BY A.SETID, A.YC_DATA_CD, C.ASOF_DT
Thanks in advance.
CREATE VIEW PS_CG_INCDATRDY_VW (SETID, YC_DATA_CD, YC_DATA_CD_TYP, ASOF_DT, YC_MKT_ISSUE_CD, CG_X_VALUE, CG_Y_VALUE, YC_PRICE, YC_COUPON) AS SELECT A.SETID , A.YC_DATA_CD , 'I' YC_DATA_CD_TYP , C.ASOF_DT ASOF_DT , ' ' YC_MKT_ISSUE_CD , 0 CG_X_VALUE , 0 CG_Y_VALUE , 0 YC_PRICE , 0 YC_COUPON FROM PS_YC_DATADEF_TBL A , PS_YC_TERM_STRUCT B , PS_YC_RATE_TBL C , PS_CG_MKTCURVES_VW D WHERE A.SETID = B.SETID AND A.YC_DATA_CD = B.YC_DATA_CD AND A.YC_DATA_CD_TYP = 'M' AND B.YC_MKT_ISSUE_CD = C.YC_MKT_ISSUE_CD AND A.SETID = D.SETID AND A.YC_DATA_CD = D.YC_DATA_CD AND C.ASOF_DT = D.ASOF_DT AND D.YC_COUNT < ( SELECT COUNT(*) FROM PS_YC_TERM_STRUCT E WHERE B.SETID = E.SETID AND B.YC_DATA_CD = E.YC_DATA_CD ) GROUP BY A.SETID, A.YC_DATA_CD, C.ASOF_DT
Thanks in advance.
ASKER
Got the same error, the funny thing is that the SELECT statement runs correctly when I run it by itself, its only when I add the CREATE VIEW clause that I get the error.
what was the error ..?
try to user create or replace, so that you run the same query multiple times instead of dropping and creating.
try to user create or replace, so that you run the same query multiple times instead of dropping and creating.
ASKER
Sorry, what I meant was when I did executed the CREATE or REPLACE view I get the ORA-00979: not a GROUP by expression. But when I execute the SELECT statement portion the query, it runs just fine without any errors.
Can you try the same removing this block,
AND D.YC_COUNT <
(SELECT COUNT ( * )
FROM PS_YC_TERM_STRUCT E
WHERE B.SETID = E.SETID AND B.YC_DATA_CD = E.YC_DATA_CD)
mean while i will try to simulate a similar scenario, to see if i will also get the same error.
AND D.YC_COUNT <
(SELECT COUNT ( * )
FROM PS_YC_TERM_STRUCT E
WHERE B.SETID = E.SETID AND B.YC_DATA_CD = E.YC_DATA_CD)
mean while i will try to simulate a similar scenario, to see if i will also get the same error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Was able to figure out the solution to the problem once I started interacting with the commenters.
CREATE OR REPLACE VIEW PS_CG_INCDATRDY_VW
(
SETID,
YC_DATA_CD,
YC_DATA_CD_TYP,
ASOF_DT,
YC_MKT_ISSUE_CD,
CG_X_VALUE,
CG_Y_VALUE,
YC_PRICE,
YC_COUPON
)
AS
SELECT A.SETID,
A.YC_DATA_CD,
max('I') YC_DATA_CD_TYP,
C.ASOF_DT ASOF_DT,
max(' ') YC_MKT_ISSUE_CD,
max(0) CG_X_VALUE,
max(0) CG_Y_VALUE,
max(0) YC_PRICE,
max(0) YC_COUPON
FROM PS_YC_DATADEF_TBL A,
PS_YC_TERM_STRUCT B,
PS_YC_RATE_TBL C,
PS_CG_MKTCURVES_VW D
WHERE A.SETID = B.SETID
AND A.YC_DATA_CD = B.YC_DATA_CD
AND A.YC_DATA_CD_TYP = 'M'
AND B.YC_MKT_ISSUE_CD = C.YC_MKT_ISSUE_CD
AND A.SETID = D.SETID
AND A.YC_DATA_CD = D.YC_DATA_CD
AND C.ASOF_DT = D.ASOF_DT
AND D.YC_COUNT <
(SELECT COUNT ( * )
FROM PS_YC_TERM_STRUCT E
WHERE B.SETID = E.SETID AND B.YC_DATA_CD = E.YC_DATA_CD)
GROUP BY A.SETID, A.YC_DATA_CD, C.ASOF_DT
you cannot use columns names in the select list with out a group function on it except the ones specified in the group by clause