簡體   English   中英

SQL查詢可在PL / SQL中使用,但不能在Visual Studio中使用

[英]SQL query works in PL/SQL but not in Visual Studio

我在網上搜索,發現很多問題相同,但是沒有一種解決方案適合我。 我真的希望您能為我提供幫助:我有一個可以在PL / SQL中正常運行的ORACLE SQL查詢:

select a.bzq_terminate_provider, a.callsnum, a.at_call_dur_sec, sum_charge 
From (select * from usage_cycle_sum 
where ban='80072922' and ben='1'
and subscriber_no='036585305'
and start_cycle_code ='20150207'
and feature_code_rank='1') a, (select bzq_terminate_provider,sum(charge_amount) as sum_charge from usage_cycle_sum 
where ban='80072922' and ben='1'
and subscriber_no='036585305'
and start_cycle_code ='20150207' group by bzq_terminate_provider)  b
where  a.bzq_terminate_provider=b.bzq_terminate_provider

我也嘗試了另一個運行良好的版本:

    select PROVIDER,sum(CALLS),sum(CHARGE),sum(DUR)
from (
select bzq_terminate_provider PROVIDER,callsnum CALLS,charge_amount CHARGE,at_call_dur_sec DUR
from   usage_cycle_sum 
where  ban='80072922' and ben='1'
  and  subscriber_no='036585305'
  and  start_cycle_code ='20150207'
  and  feature_code_rank='1'
union  
select bzq_terminate_provider PROVIDER,0 CALLS,charge_amount CHARGE,0 DUR
from   usage_cycle_sum 
where  ban='80072922' and ben='1'
  and  subscriber_no='036585305'
  and  start_cycle_code ='20150207'
  and  feature_code_rank='2'
  )
group by PROVIDER 

我的問題是,當我在Visual Studio Web應用程序中創建數據網格時,出現錯誤:語法錯誤:期望標識符或帶引號的標識符

連接正常,我在附加的第二個查詢中檢查了簡單的選擇查詢以及整個並集部分,它們起作用了! 但是當我使用這兩個版本時,會出現此錯誤。

可能是什么問題? 還有另一種解決方法嗎? 謝謝。

編輯21/06/2015看來Visual Studio不能很好地處理復雜的查詢,並且我仍在尋找解決方案,因為我的下一個查詢更加復雜...

您的第二個查詢寫得更好:

select bzq_terminate_provider as PROVIDER, sum(callsnum) as CALLS,
       sum(charge_amount) as CHARGE, sum(at_call_dur_sec) as DUR
from usage_cycle_sum 
where ban = '80072922' and ben = '1' and
      subscriber_no = '036585305' and
      start_cycle_code ='20150207' and
      feature_code_rank in ('1', '2')
group by bzq_terminate_provider ;

或者,可能需要select

select bzq_terminate_provider as PROVIDER,
       sum(case when feature = '1' then callsnum else 0 end) as CALLS,
       sum(charge_amount) as CHARGE,
       sum(case when feature = '1' then at_call_dur_sec else 0 end) as DUR

(第一個版本假定字段在第二個子查詢中被清零,因為它們在數據中為NULL ,但這可能不正確。)

但是,應用程序軟件還不夠智能,無法識別這種笨拙的查詢,因此這並不是您要面對的實際問題。 如果查詢在數據庫中有效,但在應用程序中無效,則典型問題是:

  • 該應用程序未連接到正確的數據庫。
  • 該應用程序沒有數據庫或表的權限。
  • 應用程序查詢不同於數據庫中運行的查詢,通常是由於某些替換問題。
  • 在應用程序中運行查詢的結果未正確解釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM