ORA-25154錯誤解決方法

pingley發表於2012-02-06
ORA-25154錯誤解決方法
執行SQL語句出現上述的錯誤的原因是,在Using子句中的列在select子句的查詢列表中使用了表字首。
因為using子句中的列是兩張連線的表中共有的,所以不需要也不能用表字首指明是哪張表的列。

示例:
SQL> select
  c.customer#,o.isbn,b.retail,o.paideach,nullif(paideach,retail)
  2  from books b join orderitems o using(isbn)
  3  join orders c using(order#)
  4  where c.order# in (1003,1007);
 
select c.customer#,o.isbn,b.retail,o.paideach,nullif(paideach,retail)
from books b join orderitems o using(isbn)
join orders c using(order#)
where order# in (1003,1007);
 
ORA-25154: USING 子句的列部分不能有限定詞
錯誤存在於o.isbn中.
修改以後正確執行
SQL> select c.customer#,isbn,b.retail,o.paideach,nullif(paideach,retail)
  2  from books b join orderitems o using(isbn)
  3  join orders c using(order#)
  4  where order# in (1003,1007)
  5  ;
 
CUSTOMER# ISBN        RETAIL PAIDEACH NULLIF(PAIDEACH,RETAIL)
--------- ---------- ------- -------- -----------------------
     1001 8843172113   55.95    55.95 
     1001 1059831198   30.95    30.95 
     1001 3437212490   19.95    19.95 
     1007 3957136468   75.95    72.15                   72.15
     1007 9959789321   54.50    54.50 
     1007 8117949391    8.95     8.95 
     1007 8843172113   55.95    55.95 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26110315/viewspace-715725/,如需轉載,請註明出處,否則將追究法律責任。

相關文章