我正在使用 5 个 SELECT(UNION-ed)扩展现有视图,该视图在其中一个 WHERE 子句中有一个子查询。
现在需要在所有 SELECT 语句中访问该子查询中使用的表,所以我想加入它(在此处进行一些研究之后:))。
现在的形式是这样的(简体)
SELECT DISTINCT
...
FROM
PERSON ,
ADDRESS ,
OWNER ,
OBJECT
WHERE
PERSON.PERSONID = ADDRESS.PERSONID
AND PERSON.PERSONID = OWNER.PERSONID (+)
AND OWNER.OBJECTID = OBJECT.OBJECTID
AND
(
OBJECT.REG_REQUIRED NOT in
(
'Y'
)
OR
(
OBJECT.REG_REQUIRED in ('Y')
AND OWNER.PERSONID || OWNER.OBJECTID IN
(
SELECT
REG.PERSONID || REG.OBJECTID
FROM REGISTRATIONS REG
WHERE APPROVED IN ('Y','V')
)
)
)
连接需要考虑到子查询中有串联的事实:
SELECT DISTINCT
...
FROM
PERSON ,
ADDRESS ,
OWNER ,
OBJECT ,
REGISTRATIONS REG
WHERE
PERSON.PERSONID = ADDRESS.PERSONID
AND PERSON.PERSONID = OWNER.PERSONID (+)
AND OWNER.OBJECTID = OBJECT.OBJECTID
AND
(
OBJECT.REG_REQUIRED NOT in
(
'Y'
)
OR
(
OBJECT.REG_REQUIRED in ('Y')
AND (( OWNER.PERSONID || OWNER.OBJECTID = REG.PERSONID || REG.OBJECTID ) AND REG.APPROVED IN ('Y','V'))
)
)
我这样做对吗?