Sql ORA-00904解码别名上的标识符无效
当我试图在我的Sql ORA-00904解码别名上的标识符无效,sql,oracle,alias,decode,Sql,Oracle,Alias,Decode,当我试图在我的select语句中使用decode的别名时,我遇到了标题中所述的错误。代码如下: SELECT DISTINCT rl.complaint_date, decode(rl.judgement_date,null,rl.complaint_amt,rl.judgement_amt) as account_amt, rl.date_served1, rl.date_serv
select
语句中使用decode
的别名时,我遇到了标题中所述的错误。代码如下:
SELECT DISTINCT rl.complaint_date,
decode(rl.judgement_date,null,rl.complaint_amt,rl.judgement_amt) as account_amt,
rl.date_served1,
rl.date_served2,
rl.judgement_date,
rl.skip_locate,
rl.case_no,
lcc.bal_range_min,
lcc.bal_range_max,
lcc.cost_range_min,
lcc.cost_range_max,
lcc.court,
lcc.county AS lcc_county,
ah.ACCOUNT,
ah.transaction_code,
ah.transaction_date,
ah.rule_id,
ah.amount,
ah.description,
r.state,
r.zip_code,
z.county AS ah_county,
z.county_2,
z.county_3,
z.county_4
FROM legal_address_skip las,
racctrel r,
ziplist z,
legal_court_cost lcc,
racctlgl rl,
legal_transaction_review ah
WHERE ah.ACCOUNT = rl.ACCOUNT
AND ah.ACCOUNT = las.ACCOUNT(+)
AND ah.ACCOUNT = r.ACCOUNT
AND nvl(lpad(substr(r.zip_code,0,instr(r.zip_code,'-')-1),5,0), substr(r.zip_code,1,5)) = z.zip
AND r.state = lcc.state
AND (REPLACE(lcc.county,' ','') = REPLACE(upper(z.county),' ','')
OR REPLACE(lcc.county,' ','') = REPLACE(upper(z.county_2),' ','')
OR REPLACE(lcc.county,' ','') = REPLACE(upper(z.county_3),' ','')
OR REPLACE(lcc.county,' ','') = REPLACE(upper(z.county_4),' ',''))
AND lcc.transaction_code = ah.transaction_code
AND lcc.transaction_code = 1
AND lcc.end_date IS NULL
AND ah.amount NOT BETWEEN lcc.cost_range_min AND lcc.cost_range_max
AND (account_amt NOT BETWEEN lcc.bal_range_min AND lcc.bal_range_max
OR lcc.bal_range_min - account_amt NOT BETWEEN 0 AND 500)
ORDER BY CASE
WHEN ah.amount NOT BETWEEN lcc.cost_range_min AND lcc.cost_range_max THEN 1
WHEN ah.amount BETWEEN lcc.cost_range_min AND lcc.cost_range_max THEN 2 END, ah.amount;
我以前在select语句中使用过别名,所以我不明白为什么会出现错误。在这种情况下,它的工作方式是否有所不同?(重点补充):
您可以使用列别名c\u alias
,立即为
选择列表中的前一个表达式,以便列
以新标题显示。别名有效地重命名了select
查询持续时间的列表项别名可在中使用
orderby
子句,但不包括查询中的其他子句。
因此,您不能在where
子句中引用别名,此时您有:
...
AND (account_amt NOT BETWEEN ...
...
别名此时无效,因此它正在其中一个表中查找具有该名称的列,但未找到该列。不过,按的顺序就可以了
您需要使用重复的
decode
语句替换别名,或者可能使用子查询,然后在外部查询中的where
子句中引用别名,但这可能会降低效率,具体取决于您的其他条件的选择性。Oracle按以下顺序运行select查询:
WITH q AS
(
-- Your query without the extra AND
)
SELECT *
FROM q
WHERE --put your check here
这样,当您到达WHERE零件时,别名就已经可用了
希望这有帮助!:) 查询正在WHERE子句中使用
和(account\u amt NOT BETWEEN
。是否有任何表包含名为account\u amt
的列?感谢您提供的有用提示!