查询在 PLSQL Developer 中有效,但在 SQL Developer 中无效

Query works in PLSQL Developer but doesn't in SQL Developer

所以,我有这个查询让我发疯。出于某种疯狂的原因,查询运行并在 PLSQL Developer 上带来了所需的输出,但在 SQL Developer 上却没有!据我所知,完全相同的查询应该适用于两者,而不仅仅是一个或另一个。并非我团队中的每个人都拥有 PLSQL Dev,因此它必须同时适用于两者。此查询还在我的 BI 应用程序上显示了不同的行为。有人见过这种疯狂的行为吗?

查询如下:

with t1 as (
SELECT
  case  when CLG_STATUS.NM_STATUS in ('1 - ATIVO','5 - BLOQUEADO','7 - AGUARDANDO AUTENTICAÇÃO') then 'LG Club Member'
    else 'Non  Member' 
  end membership,
  Round(
    Round(SUM(NVL(CASE WHEN CLG_VENDA.CD_TP_VENDA = 'D' THEN -1*CLG_VENDA.QTD_VENDA ELSE CLG_VENDA.QTD_VENDA END,0)), 1) 
    /
   Count(distinct CLG_PARTICIPANTE.ID)
  , 1) as average_sales ,
  Round(
    SUM(NVL(CASE WHEN CLG_VENDA.CD_TP_VENDA = 'D' THEN -1*CLG_VENDA.QTD_VENDA ELSE CLG_VENDA.QTD_VENDA END,0))
  , 1) as sellout, 
  Count(distinct CLG_PARTICIPANTE.ID)
  as "qty members"
FROM
  CLG_VENDA_PONTO,
  CLG_PARTICIPANTE,
  CLG_STATUS,
  CLG_VENDA,
  CLG_CARGO  CLG_CARGO_VENDA,
  CLG_CANAL  CLG_CANAL_VENDA,
  CLG_REDE  CLG_REDE_VENDA,
  CLG_PRODUTO,
  CLG_TP_MOVIMENTO,
  DIM_PERIOD_DAY  PERIOD_VENDA_DATA,
  CLG_LOJA  CLG_LOJA_VENDA
WHERE
  ( CLG_VENDA_PONTO.ID_VENDA=CLG_VENDA.ID(+)  )
  AND  ( CLG_VENDA_PONTO.ID_PROD=CLG_PRODUTO.ID(+)  )
  AND  ( CLG_VENDA_PONTO.ID_CARGO=CLG_CARGO_VENDA.ID  )
  AND  ( CLG_LOJA_VENDA.ID=CLG_VENDA_PONTO.ID_LOJA  )
  AND  ( CLG_REDE_VENDA.ID=CLG_LOJA_VENDA.ID_REDE  )
  AND  ( CLG_CANAL_VENDA.ID=CLG_VENDA_PONTO.ID_CANAL  )
  AND  ( CLG_PARTICIPANTE.ID_LOJA=CLG_LOJA_VENDA.ID  )
  AND  ( CLG_LOJA_VENDA.ID_REDE=CLG_REDE_VENDA.ID  )
  AND  ( CLG_PARTICIPANTE.ID=CLG_VENDA_PONTO.ID_PARTCPTE  )
  AND  ( CLG_VENDA_PONTO.ID_TP_MOVIMENTO=CLG_TP_MOVIMENTO.ID  )
  AND  ( CLG_STATUS.ID=CLG_PARTICIPANTE.ID_STATUS  )
  AND  ( CLG_VENDA_PONTO.DATA_VENDA=PERIOD_VENDA_DATA.YYYYMMDD  )
  AND  ( CLG_CARGO_VENDA.NM_CARGO = '5 - VENDEDOR' OR CLG_VENDA.ID_CARGO = 8  )
  AND  
  (
   CLG_PRODUTO.NM_PRODUTO  NOT IN  ( 'M4338 - FRETE','R39745 - FRETE SOBRE VENDAS'  )
   AND
   CLG_TP_MOVIMENTO.NM_MOVIMENTO  IN  ( '1 - VENDA','3 - DEVOLUCAO'  )
   AND
   CLG_REDE_VENDA.NM_REDE  =  '21540901 - RABELO'
   AND
   PERIOD_VENDA_DATA.YYYYMMDD_DATE  BETWEEN  to_date('01-01-2013', 'DD-MM-YYYY')  AND  to_date('31-12-2013', 'DD-MM-YYYY')
   AND
   CLG_CANAL_VENDA.NM_CANAL  IN  ('1 - VAREJO')
   AND
   CLG_PRODUTO.FG_MAPEADO  IN  ( 'SIM'  )
  )
GROUP BY
  case  when CLG_STATUS.NM_STATUS in ('1 - ATIVO','5 - BLOQUEADO','7 - AGUARDANDO AUTENTICAÇÃO') then 'LG Club Member'
    else 'Non  Member' 
  end
), t2 as (
SELECT
  case  when CLG_STATUS.NM_STATUS in ('1 - ATIVO','5 - BLOQUEADO','7 - AGUARDANDO AUTENTICAÇÃO') then 'LG Club Member'
    else 'Non  Member' 
  end membership,
  Round(
    Round(SUM(NVL(CASE WHEN CLG_VENDA.CD_TP_VENDA = 'D' THEN -1*CLG_VENDA.QTD_VENDA ELSE CLG_VENDA.QTD_VENDA END,0)), 1) 
    /
   Count(distinct CLG_PARTICIPANTE.ID)
  , 1) as average_sales ,
  Round(
    SUM(NVL(CASE WHEN CLG_VENDA.CD_TP_VENDA = 'D' THEN -1*CLG_VENDA.QTD_VENDA ELSE CLG_VENDA.QTD_VENDA END,0))
  , 1) as sellout, 
  Count(distinct CLG_PARTICIPANTE.ID)
  as "qty members" 
FROM
  CLG_VENDA_PONTO,
  CLG_PARTICIPANTE,
  CLG_STATUS,
  CLG_VENDA,
  CLG_CARGO  CLG_CARGO_VENDA,
  CLG_CANAL  CLG_CANAL_VENDA,
  CLG_REDE  CLG_REDE_VENDA,
  CLG_PRODUTO,
  CLG_TP_MOVIMENTO,
  DIM_PERIOD_DAY  PERIOD_VENDA_DATA,
  CLG_LOJA  CLG_LOJA_VENDA
WHERE
  ( CLG_VENDA_PONTO.ID_VENDA=CLG_VENDA.ID(+)  )
  AND  ( CLG_VENDA_PONTO.ID_PROD=CLG_PRODUTO.ID(+)  )
  AND  ( CLG_VENDA_PONTO.ID_CARGO=CLG_CARGO_VENDA.ID  )
  AND  ( CLG_LOJA_VENDA.ID=CLG_VENDA_PONTO.ID_LOJA  )
  AND  ( CLG_REDE_VENDA.ID=CLG_LOJA_VENDA.ID_REDE  )
  AND  ( CLG_CANAL_VENDA.ID=CLG_VENDA_PONTO.ID_CANAL  )
  AND  ( CLG_PARTICIPANTE.ID_LOJA=CLG_LOJA_VENDA.ID  )
  AND  ( CLG_LOJA_VENDA.ID_REDE=CLG_REDE_VENDA.ID  )
  AND  ( CLG_PARTICIPANTE.ID=CLG_VENDA_PONTO.ID_PARTCPTE  )
  AND  ( CLG_VENDA_PONTO.ID_TP_MOVIMENTO=CLG_TP_MOVIMENTO.ID  )
  AND  ( CLG_STATUS.ID=CLG_PARTICIPANTE.ID_STATUS  )
  AND  ( CLG_VENDA_PONTO.DATA_VENDA=PERIOD_VENDA_DATA.YYYYMMDD  )
  AND  ( CLG_CARGO_VENDA.NM_CARGO = '5 - VENDEDOR' OR CLG_VENDA.ID_CARGO = 8  )
  AND  
  (
   CLG_PRODUTO.NM_PRODUTO  NOT IN  ( 'M4338 - FRETE','R39745 - FRETE SOBRE VENDAS'  )
   AND
   CLG_TP_MOVIMENTO.NM_MOVIMENTO  IN  ( '1 - VENDA','3 - DEVOLUCAO'  )
   AND
   CLG_REDE_VENDA.NM_REDE  =  '21540901 - RABELO'
   AND
   PERIOD_VENDA_DATA.YYYYMMDD_DATE  BETWEEN  add_months(to_date('01-01-2013', 'DD-MM-YYYY'), -12)  AND  add_months(to_date('31-12-2013', 'DD-MM-YYYY'), -12)
   AND
   CLG_CANAL_VENDA.NM_CANAL  IN  ('1 - VAREJO')
   AND
   CLG_PRODUTO.FG_MAPEADO  IN  ( 'SIM'  )
  )
GROUP BY
  case  when CLG_STATUS.NM_STATUS in ('1 - ATIVO','5 - BLOQUEADO','7 - AGUARDANDO AUTENTICAÇÃO') then 'LG Club Member'
    else 'Non  Member' 
  end
)
select t1.*, coalesce((t1.average_sales - t2.average_sales) / t2.average_sales, 0)    as variation
from t1 join t2 on t1.membership = t2.membership

在 SQL 开发者上显示:

ORA-00928: missing SELECT keyword
00928. 00000 -  "missing SELECT keyword"

我在这里完全不知所措。查询如何在一个工具而不是另一个工具上解析?我尝试在网上搜索但无济于事。 提前致谢!

可能是这条线,

    /

SQL Plus 本身使用 / 来标记 sql 查询的结束,并且 SQL 开发人员很可能会遵循。但是,前面的空格可能会改变意思,所以这可能不是问题所在。

要检验这个假设,请将 / 移动到前一行。变化

    Round(SUM(NVL(CASE WHEN CLG_VENDA.CD_TP_VENDA = 'D' THEN -1*CLG_VENDA.QTD_VENDA ELSE CLG_VENDA.QTD_VENDA END,0)), 1) 
    /
   Count(distinct CLG_PARTICIPANTE.ID)

    Round(SUM(NVL(CASE WHEN CLG_VENDA.CD_TP_VENDA = 'D' THEN -1*CLG_VENDA.QTD_VENDA ELSE CLG_VENDA.QTD_VENDA END,0)), 1) /
   Count(distinct CLG_PARTICIPANTE.ID)

如果那是问题所在,那么需要重新格式化为适合您的格式,并且不会让 / 单独一行。