1

次のSQLを使用してデータベースにクエリを実行しようとしています:

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 (+);

オラクルで実行すると正常に動作します。Java からクエリを実行しようとすると、"bad sql grammar" と表示されます。

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

私は何が欠けていますか?

4

1 に答える 1

0

Java の実行時に使用している oracle ログインが、oracle でクエリを実行するときに使用しているものとは異なる可能性があります。この場合、次のいずれかがおそらく答えです。

  1. Java ログインには、おそらく問題のテーブルまたはビューに対する選択権限がありません。
  2. Java ログイン スキーマは Oracle ログイン スキーマと同じではなく (それらは異なるログインであり、すべて)、Java ログインのクエリにはテーブル (または複数のテーブル) の同義語はありません。この場合は、テーブル名にスキーマを追加します (例: blammy.table_name)。

使用しているテーブル (dba_temp_blah) に基づいて、1 が anser であると思われます。

于 2013-08-02T13:49:30.163 に答える