我不倾向于提出有关错误的问题,但是在我正在做的每一份报告中都会发生这种错误。我的方法存在根本性的问题,我需要一个解决方案,如果可能的话,希望能有一个解释。我需要转换多个报告,并且每个人都会以这种或那种方式收到此错误。
这是我的代码。
我收到了无效的标识符:
INNER JOIN Unit_instance_occurrences uio
ON uio.offering_organisation = ou.organisation_code
我不明白 ou 标识符已已定义。
以下是完整代码:
SELECT pu.CALOCC_CODE,
ou.FES_FULL_NAME,
pu.UIO_ID,
uio.FES_UINS_INSTANCE_CODE ||' '||uio.LONG_DESCRIPTION Crse_Desc,
EBS_TUTORGROUPSLIST_SEL(pu.id,pu.UIO_ID) Grp,
pu.PERSON_CODE,
p.FORENAME,
p.SURNAME,
Upper(p.surname) ||', '||p.forename||' ('||pu.person_code||')' Student,
pu.PROGRESS_CODE,
pu.PROGRESS_STATUS,
pu.PROGRESS_DATE,
Marks.Absent,
Marks.Late,
Marks.Not_Expected,
Marks.Present,
Marks.Notified_Absence,
Marks.Blanks,
SUM( Marks.Absent+ Marks.Late+ Marks.Not_Expected+ Marks.Present+ Marks.Notified_Absence+ Marks.Blanks ) Poss_Marks
FROM people p,
organisation_units ou,
(SELECT red.session_code,
red.OBJECT_ID UIO_ID,
reds.person_code,
SUM(reds.absent) Absent,
SUM(reds.late) Late,
SUM(reds.not_expected) Not_Expected,
SUM(reds.present) Present,
SUM(reds.notified_Absence) Notified_Absence,
SUM(reds.blanks) Blanks
FROM
(SELECT reds.OBJECT_ID Person_Code,
reds.REGISTER_EVENT_ID,
reds.SESSION_CODE,
-- COUNT(DECODE(reds.USAGE_CODE, 'O', 1)) Absent,
--COUNT(DECODE(reds.USAGE_CODE, 'L', 1)) Late,
--COUNT(DECODE(reds.USAGE_CODE, 'V', 1)) Not_Expected,
-- COUNT(DECODE(reds.USAGE_CODE, '/', 1)) Present,
-- COUNT(DECODE(reds.USAGE_CODE, 'X', 1)) Notified_Absence,
-- COUNT(DECODE(reds.USAGE_CODE, NULL, 1)) Blanks
FROM register_event_details_slots reds
WHERE reds.session_code = :P_Occurrence --Added Params from master
AND reds.object_type = 'L'
AND reds.planned_end_date <= Sysdate) reds
INNER JOIN register_event_details red
ON red.register_event_id = reds.register_event_id
AND red.session_code = reds.session_code
WHERE
--red.REGISTER_EVENT_ID = reds.REGISTER_EVENT_ID
--and red.SESSION_CODE = reds.SESSION_CODE
red.OBJECT_TYPE = 'U'
) Marks
INNER JOIN Unit_instance_occurrences uio
ON uio.offering_organisation = ou.organisation_code
INNER JOIN people_units pu
ON pu.CALOCC_CODE = Marks.session_code --(+)
AND pu.PERSON_CODE = Marks.person_code --(+)
AND pu.UIO_ID = Marks.UIO_ID --(+)
AND pu.uio_id = uio.uio_id
AND pu.person_code = p.person_code
WHERE
--pu.CALOCC_CODE = Marks.session_code --(+)
--and pu.PERSON_CODE = Marks.person_code --(+)
--and pu.UIO_ID = Marks.UIO_ID --(+)
--pu.UIO_ID = uio.UIO_ID
--and uio.OFFERING_ORGANISATION = ou.ORGANISATION_CODE
--and pu.person_code = p.PERSON_CODE
pu.UNIT_TYPE = 'R'
AND pu.CALOCC_CODE = :P_Occurrence -- Added Params from master
AND uio.owning_organisation = :P_Faculty
AND uio.OFFERING_ORGANISATION = :P_Division
AND uio.UIO_ID IS NOT NULL
AND uio.FES_ACTIVE = 'Y'
答案 0 :(得分:1)
您已在最外面的select语句中定义,您无法在内部select语句中使用它。
此外,如果您的SQL看起来像这样,您应该考虑使用内部select语句的视图将其制动为较小的部分。以这种方式开发和调试会容易得多。
此外,Ben说。坚持一种语法。
答案 1 :(得分:1)
如果我重新组织您的联接,我会得到以下内容, 不 混合隐式(使用,
)和显式连接(使用INNER JOIN
等)。
SELECT
blah
FROM
organisation_units ou
INNER JOIN
Unit_instance_occurrences uio
ON uio.offering_organisation = ou.organisation_code
INNER JOIN
people_units pu
ON pu.uio_id = uio.uio_id
INNER JOIN
people p
ON p.person_code = pu.person_code
INNER JOIN
(
yourSubQuery
)
Marks
ON pu.CALOCC_CODE = Marks.session_code --(+)
AND pu.PERSON_CODE = Marks.person_code --(+)
AND pu.UIO_ID = Marks.UIO_ID --(+)
WHERE
--pu.CALOCC_CODE = Marks.session_code --(+)
--and pu.PERSON_CODE = Marks.person_code --(+)
--and pu.UIO_ID = Marks.UIO_ID --(+)
--pu.UIO_ID = uio.UIO_ID
--and uio.OFFERING_ORGANISATION = ou.ORGANISATION_CODE
--and pu.person_code = p.PERSON_CODE
pu.UNIT_TYPE = 'R'
AND pu.CALOCC_CODE = :P_Occurrence -- Added Params from master
AND uio.owning_organisation = :P_Faculty
AND uio.OFFERING_ORGANISATION = :P_Division
AND uio.UIO_ID IS NOT NULL
AND uio.FES_ACTIVE = 'Y'
然而,我更关心的是你已经注释了许多(+)
。这些是允许OUTER
连接的过时语法。这意味着上面的查询仍然需要重新处理,并且可能需要重新排序以适应任何适当的LEFT JOIN
等。