我的full outer join子句中出现无效的标识符错误。我认为这可能与我的select语句有关,但不确定在哪里。 以下是查询:
select h.laborlev2nm "Labor Acct", h.laborlev2dsc "Dept Name",
to_char(b.pay_date, 'MM/DD/YYYY') as "PDate",
to_char(d.start_date, 'MM/DD/YYYY') as "SDate",
to_char(d.end_date, 'MM/DD/YYYY') as "EDate",
c.personnum "ID", c.fullnm "FullName",
d.pay_type "Pay Type", f.name "Paycode", f.paycode_id "Paycode ID",
j.dags_objectcode "DAGS", NULL AS "Raw Hours",
'Regular' AS "Retro Paycode Name",
101 AS "Retro Paycode ID", 0 AS "Computed Hours", 0 AS "Retro Hours",
CASE
WHEN f.name = 'CH to Salaried Reg Pay Adj' THEN li.amount
WHEN f.name = 'Change in BU Reg Pay Adj' THEN li.amount
WHEN f.name = 'FTE Change Reg Pay Adj' THEN li.amount
WHEN f.name = 'LOA Overpayment Adjustment' THEN li.amount
WHEN f.name = 'LOA Underpayment Adjustment' THEN li.amount
WHEN f.name = 'New Hire Reg Pay Adj' THEN li.amount
WHEN f.name = 'Overpayment Adjustment' THEN li.amount
WHEN f.name = 'Retro Adjustment' THEN li.amount
WHEN f.name = 'Salaried to CH Reg Pay Adj' THEN li.amount
WHEN f.name = 'Termination Pay Adj' THEN li.amount
WHEN f.name = 'Underpayment Adjustment' THEN li.amount
ELSE NULL
END AS "Retro Dollars",
b.gross_pay "Gross", c.ftepct "FTE", 'Regular' "Reg/Cas", bu.external_key "BU",
d.pay_adjustment_id "Pay Adj ID", d.hourly_rate "H Rate", d.pay_type "P type"
--jc.jobtitledsc "Job Title"
from
TKCSOWNER.KSS_EMP_JOB_INFO a , TKCSOWNER.KSS_PAYROLL b, TKCSOWNER.PERSON c,
TKCSOWNER.KSS_PAYROLL_DETAIL d, TKCSOWNER.KSS_PAYCODE_MAP f, TKCSOWNER.KSS_BARGAINING_UNIT BU,
TKCSOWNER.LABORACCT h, TKCSOWNER.KSS_DAGSPAY_OBJCD_MAP j
full outer join TKCSOWNER.KSS_PAY_ADJ_LINE_ITEM li on (d.pay_adjustment_id = li.pay_adjustment_id)
该错误表明我的d.pay_adjustment_id是最后一行代码的无效标识符。
感谢您提前获取任何建议
答案 0 :(得分:1)
正如在评论和接受的答案中所讨论的那样,你绝不应该混合使用Oracle"逗号语法"和SQL标准(ANSI)语法在同一查询中连接。这不是非法的,但语法规则是如此复杂,你不可能让它们正确 - 而且,没有理由这样做。
针对您的具体问题:
该错误与上次加入外部连接无关。如果将其更改为内部连接,则会出现相同的错误。相反:当您混合使用Oracle语法和ANSI语法时,首先使用ANSI语法进行连接,就像括在括号中一样。您是全外连接(或实际上是ANSI连接)别名j
和li
的表。此时,只有名称j
和li
在范围内;此时d
不可见。这就是它告诉你的错误信息。
您可以非常轻松地重新创建相同的问题:
SQL> select 1 from dual a, dual b inner join dual c on a.dummy = c.dummy;
select 1 from dual a, dual b inner join dual c on a.dummy = c.dummy
*
ERROR at line 1:
ORA-00904: "A"."DUMMY": invalid identifier
相反:
SQL> select 1 from dual a, dual b inner join dual c on b.dummy = c.dummy;
1
----------
1
您已经在接受的答案中使用正确的方法。
答案 1 :(得分:0)
当表格用逗号分隔并且通过where子句包含其他任何内容以限制效果时,您正在创建一个CROSS JOIN。所以每个逗号都有一个CROSS JOIN。
这就是我理解您的查询的方式,它涉及多表笛卡尔积:
SELECT h.laborlev2nm "Labor Acct"
, h.laborlev2dsc "Dept Name"
, to_char(b.pay_date, 'MM/DD/YYYY') AS "PDate"
, to_char(d.start_date, 'MM/DD/YYYY') AS "SDate"
, to_char(d.end_date, 'MM/DD/YYYY') AS "EDate"
, c.personnum "ID"
, c.fullnm "FullName"
, d.pay_type "Pay Type"
, f.NAME "Paycode"
, f.paycode_id "Paycode ID"
, j.dags_objectcode "DAGS"
, NULL AS "Raw Hours"
, 'Regular' AS "Retro Paycode Name"
, 101 AS "Retro Paycode ID"
, 0 AS "Computed Hours"
, 0 AS "Retro Hours"
, CASE WHEN f.NAME = 'CH to Salaried Reg Pay Adj' THEN li.amount WHEN f.NAME = 'Change in BU Reg Pay Adj' THEN li.amount WHEN f.NAME = 'FTE Change Reg Pay Adj' THEN li.amount WHEN f.NAME = 'LOA Overpayment Adjustment' THEN li.amount WHEN f.NAME = 'LOA Underpayment Adjustment' THEN li.amount WHEN f.NAME = 'New Hire Reg Pay Adj' THEN li.amount WHEN f.NAME = 'Overpayment Adjustment' THEN li.amount WHEN f.NAME = 'Retro Adjustment' THEN li.amount WHEN f.NAME = 'Salaried to CH Reg Pay Adj' THEN li.amount WHEN f.NAME = 'Termination Pay Adj' THEN li.amount WHEN f.NAME = 'Underpayment Adjustment' THEN li.amount ELSE NULL END AS "Retro Dollars"
, b.gross_pay "Gross"
, c.ftepct "FTE"
, 'Regular' "Reg/Cas"
, bu.external_key "BU"
, d.pay_adjustment_id "Pay Adj ID"
, d.hourly_rate "H Rate"
, d.pay_type "P type"
--jc.jobtitledsc "Job Title"
FROM TKCSOWNER.KSS_EMP_JOB_INFO a
CROSS JOIN TKCSOWNER.KSS_PAYROLL b
CROSS JOIN TKCSOWNER.PERSON c
CROSS JOIN TKCSOWNER.KSS_PAYROLL_DETAIL d
CROSS JOIN TKCSOWNER.KSS_PAYCODE_MAP f
CROSS JOIN TKCSOWNER.KSS_BARGAINING_UNIT BU
CROSS JOIN TKCSOWNER.LABORACCT h
CROSS JOIN TKCSOWNER.KSS_DAGSPAY_OBJCD_MAP j
FULL JOIN TKCSOWNER.KSS_PAY_ADJ_LINE_ITEM li ON (d.pay_adjustment_id = li.pay_adjustment_id)