2012-02-15 80 views
1

當從Oracle 10g中遷移到11g中,我有一個存儲過程語法,如:的Oracle 11g別名查詢

select * from table1 
union 
select t,y from 
(select * from table2)aliasQuery 
where t=aliasQuery.t 

查詢效果很好按10g但11克返回aliasQuery沒有定義的錯誤。

也許這種語法在11g中不再支持,或者有一些缺失的數據庫配置?

編輯

完整的查詢是:

select * 
    from table1 
union 
select t, y 
    from (select * 
      from table2) aliasQuery 
where (select max(t) 
      from (select t 
        from table3 
        where table3.t = aliasQuery.t) 
       )>10 
+0

該語法在11g中正常工作。你說它是存儲過程的一部分,你能提供所有的代碼嗎?另外,你能提供返回的確切錯誤嗎? – 2012-02-15 10:29:34

+0

SELECT * FROM表1 工會 選擇T,Y從 (SELECT * FROM表2)aliasQuery 其中(選擇從最大值(T)(從表3,其中表3噸= aliasQuery.t) – Hadad 2012-02-15 10:54:06

+0

錯誤選擇噸:無效識別符aliasQuery.t – Hadad 2012-02-15 10:56:38

回答

3

根據Ask Tom的文章「Is there some sort of nesting limit for correlated subqueries?」,看起來相關的子查詢別名工作超過一個級別是一個已修復的錯誤。看起來您的10g數據庫在您的11g中沒有修復錯誤。我在10g數據庫上試過了你的查詢,並且在我的11g數據庫上出現了同樣的錯誤:ORA-00904: "ALIASQUERY"."T": invalid identifier

你將不得不改變查詢一下,讓它在11g中工作。

+0

+1很高興知道! – 2012-02-15 14:57:15

2

我可以證實,這是行不通的。我得到同樣的錯誤,你:

select t, y 
    from (select 1 t, 2 y 
      from dual) aliasQuery 
where (select max(t) 
      from (select t 
        from (select 1 as t from dual) table3 
        where table3.t = aliasQuery.t) 
       )>10 

但這:

select t, y 
    from (select 1 t, 2 y 
      from dual) aliasQuery 
where (select max(t) 
      from (select 1 as t from dual) table3 
      where table3.t = aliasQuery.t 
     )>10 

翻譯爲您查詢,您將不得不改寫爲這樣的:

select * 
    from table1 
union 
select t, y 
    from (select * 
      from table2) aliasQuery 
where (select max(t) 
      from table3 -- no need to add yet another nested select here 
      where table3.t = aliasQuery.t) 
     )>10 

我不能」告訴你爲什麼你的語法不再工作。它對我來說很好。顯然,表格重命名的範圍不會再達到雙重嵌套選擇,這讓我覺得有點可怕!