2013-08-02 38 views
0

我嘗試使用下面的SQL查詢數據庫:壞的SQL語法 - 的Java JDBC

select round(b.Used_space*100/a.tablespace_size,2) 
from 
(select tablespace_name,sum(bytes/1024/1024/1024) tablespace_size, sum(decode(MAXBYTES,0,bytes/1024/1024/1024,MAXBYTES/1024/1024/1024)) max_tablespace_size 
from dba_temp_files group by tablespace_name) a, 
(select x.TABLESPACE tablespace_name,sum(x.blocks*y.block_size/1024/1024/1024) used_space from v$sort_usage x , dba_tablespaces y where x.tablespace=y.tablespace_name group by x.TABLESPACE) b 
where a.tablespace_name=b.tablespace_name (+); 

當在Oracle運行正常工作。當我嘗試從java執行查詢時,我得到「錯誤的sql語法」。

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [select a.tablespace_name,a.tablespace_size Allocated_space_IN_GB, round(b.Used_space,2) Used_Space_in_GB, round(b.Used_space*100/a.tablespace_size,2) "Used%", a.max_tablespace_size MAX_tablespace_size_IN_GB ,round(b.used_space*100/a.max_tablespace_size,2) "Max_Alloc_Used%" from (select tablespace_name,sum(bytes/1024/1024/1024) tablespace_size, sum(decode(MAXBYTES,0,bytes/1024/1024/1024,MAXBYTES/1024/1024/1024)) max_tablespace_size from dba_temp_files group by tablespace_name) a, (select x.TABLESPACE tablespace_name,sum(x.blocks*y.block_size/1024/1024/1024) used_space from v$sort_usage x , dba_tablespaces y where x.tablespace=y.tablespace_name group by x.TABLESPACE) b where a.tablespace_name=b.tablespace_name (+)]; nested exception is java.sql.SQLException: ORA-00942: table or view does not exist 

Caused by: java.sql.SQLException: ORA-00942: table or view does not exist 

我在想什麼?

+1

顯示java代碼。 – piokuc

+1

向我們展示了關於java代碼... –

+0

您應該停止在where語句的隱式連接中使用(不建議使用)的Oracle特定外連接運算符'(+)'並使用'OUTER JOIN'開始使用顯式連接運營商 –

回答

0

運行java時使用的oracle登錄似乎可能與在oracle中運行查詢時使用的不同。如果是這種情況,那麼其中之一可能是這樣的答案:

  1. java登錄可能性在表或視圖中沒有select priviledge。
  2. java登錄架構與oracle登錄架構不同(它們是不同的登錄名和全部),並且在java登錄中的查詢中沒有表(或多個表)的同義詞。如果是這種情況,請將模式添加到表名(例如blammy.table_name)。

根據你使用的表(dba_temp_blah),我懷疑1是anser。