I'm trying to create a materialized view in Oracle 11.1, which apparently does not support nested selects in a materialized view (Why this is, I haven't been able to figure out).. Is there a way to write this query to work as a materialized view? Thanks!
CREATE MATERIALIZED VIEW MV_Area90DayReport
NOLOGGING
CACHE
BUILD IMMEDIATE
REFRESH FAST ON COMMIT
AS
select
T.TASKID,
V.PROJECTID,
V.VERSIONID,
T.GOLDDATE,
P.BUSINESSLAUNCHDATE,
V.NAME as ProjectName,
T.NAME as TaskName,
T.COURSECODE,
DT.NAME as DeliveryMethod,
T.DELIVERABLELENGTHHOUR,
T.DELIVERABLELENGTHMINUTE,
V.PRIORITY,
(SELECT MIN(STARTDATE) FROM TPM_TRAININGPLAN WHERE PROJECTID=V.PROJECTID AND TRAININGPLANTYPE='prescribed') as TrainingDeliveryDate,
(SELECT wm_concat(WORKGROUPID) FROM TPM_PROJECTWORKGROUPS WHERE PROJECTID=V.PROJECTID GROUP BY PROJECTID) as Workgroups,
from TPM_TASK T
inner join TPM_PROJECTVERSION V ON (V.PROJECTID = T.PROJECTID AND V.VERSIONID = T.VERSIONID)
inner join TPM_PROJECT P ON (P.PROJECTID = T.PROJECTID)
inner join TPM_DOCUMENTTYPE DT ON (DT.DOCUMENTTYPEID = T.DOCUMENTTYPEID);
The error I get is:
>[Error] Script lines: 1-25 -----------开发者_如何学Go--------------
ORA-22818: subquery expressions not allowed here
Script line 20, statement line 20, column 115
I believe this is a limitation (that was raised as a bug sometime back), documented here on the Oracle site - http://download.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#sthref431
To resolve, you should use JOINS rather than subqueries.
Try the following query:
select
T.TASKID,
V.PROJECTID,
V.VERSIONID,
T.GOLDDATE,
P.BUSINESSLAUNCHDATE,
V.NAME as ProjectName,
T.NAME as TaskName,
T.COURSECODE,
DT.NAME as DeliveryMethod,
T.DELIVERABLELENGTHHOUR,
T.DELIVERABLELENGTHMINUTE,
V.PRIORITY,
TP.TrainingDeliveryDate,
WG.Workgroups,
from TPM_TASK T
inner join TPM_PROJECTVERSION V ON (V.PROJECTID = T.PROJECTID AND V.VERSIONID = T.VERSIONID)
inner join TPM_PROJECT P ON (P.PROJECTID = T.PROJECTID)
inner join TPM_DOCUMENTTYPE DT ON (DT.DOCUMENTTYPEID = T.DOCUMENTTYPEID)
left join (
SELECT PROJECTID, MIN(STARTDATE) as TrainingDeliveryDate
FROM TPM_TRAININGPLAN
WHERE TRAININGPLANTYPE='prescribed'
GROUP BY PROJECTID
) TP on TP.PROJECTID=V.PROJECTID
left join (
SELECT PROJECTID, wm_concat(WORKGROUPID) as Workgroups
FROM TPM_PROJECTWORKGROUPS
GROUP BY PROJECTID
) WG on WG.PROJECTID=V.PROJECTID
精彩评论