我得到了一个oracle sql查询,它在oracle sql开发人员上运行正常,但是当我从Java编写的语句中运行它时,sql异常被抛出为“ORA-00942:表或视图不存在”并且用户获得了所有提到的权限3个架构。 查询有什么问题吗?目前我似乎无法找到问题,仍然调试sql字符串也可以在SQL开发人员中执行。
SQL查询
SELECT CLI_CLIENT.NAME ,CLI_CLIENT.CLIENT_ID,
AA.SEARCHES,
(SELECT COUNT(*) FROM RES_BOOKING,CLI_WEB_USER WHERE RES_BOOKING.BOOKED_USER=CLI_WEB_USER.ADM_USER_ID
AND TRUNC(RES_BOOKING.BOOKING_DATE) BETWEEN '01-MAR-16' AND '24-MAR-16' AND CLI_WEB_USER.CLIENT_ID=CLI_CLIENT.CLIENT_ID)AS BOOKINGS
FROM CLI_CLIENT,
(SELECT CWU.CLIENT_ID,
COUNT(ST.OPERATION) AS SEARCHES
FROM STAT.ST_TRANSACTION ST , CLI_WEB_USER CWU , CACHE.CACC_CRITERIA CC , CACHE.CACC_CRITERIA_STATS CS
WHERE ST.USER_NAME=CWU.USERNAME
AND ST.OPERATION LIKE 'OTA_HotelAvailRQ%'
AND TRUNC(ST.TRS_TIMESTAMP) BETWEEN '01-MAR-16' AND '24-MAR-16'
AND CWU.CLIENT_ID IN (10975,10040)
AND CC.CRITERIA_ID=CS.CRITERIA_ID
AND CS.SESSION_ID=ST.SESSION_ID
AND CS.DISTRIBUTION_CHANNEL='W'
GROUP BY CLIENT_ID, CWU.CLIENT_ID
)AA
WHERE CLI_CLIENT.CLIENT_ID=AA.CLIENT_ID;
Java异常
java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
答案 0 :(得分:2)
检查您是否在SQL Developer和Java应用程序中的同一用户帐户下连接到数据库。很可能情况并非如此,您的Java应用程序无法访问查询中的一个或多个表。
答案 1 :(得分:1)
以下是您在更好的视图和效果中的查询:
select C.NAME,
C.CLIENT_ID,
AA.SEARCHES,
(select count(1)
from RES_BOOKING R
join CLI_WEB_USER U
on U.ADM_USER_ID = R.BOOKED_USER
and trunc(R.BOOKING_DATE)
between '01-MAR-16'
and '24-MAR-16'
and U.CLIENT_ID = C.CLIENT_ID
) AS BOOKINGS
from CLI_CLIENT C
join
(select CWU.CLIENT_ID as CLIENT,
count(ST.OPERATION) AS SEARCHES
from STAT.ST_TRANSACTION ST
join CLI_WEB_USER CWU
on CWU.USERNAME = ST.USER_NAME
join CACHE.CACC_CRITERIA CC
on CC.CRITERIA_ID = CS.CRITERIA_ID
join CACHE.CACC_CRITERIA_STATS CS
on CS.SESSION_ID = ST.SESSION_ID
where ST.OPERATION like 'OTA_HotelAvailRQ%'
and trunc(ST.TRS_TIMESTAMP)
between '01-MAR-16'
and '24-MAR-16'
and CWU.CLIENT_ID in (10975,10040)
and CS.DISTRIBUTION_CHANNEL='W'
group by CLIENT_ID, CLIENT -- OLD OF CLIENT -> CWU.CLIENT_ID
) AA
on AA.CLIENT = C.CLIENT_ID; -- OLD OF AA.CLIENT -> AA.CLIENT_ID
然后将查询分成块并逐个执行。例如,
第一部分:
select C.NAME,
C.CLIENT_ID,
(select count(1)
from RES_BOOKING R
join CLI_WEB_USER U
on U.ADM_USER_ID = R.BOOKED_USER
and trunc(R.BOOKING_DATE)
between '01-MAR-16'
and '24-MAR-16'
and U.CLIENT_ID = C.CLIENT_ID
) AS BOOKINGS
from CLI_CLIENT C;
第二部分:取JOIN块内的代码,依此类推。如果您在该区块中出现错误,请再划分并继续此操作。