很抱歉我的菜鸟问题,但我想弄清楚为什么我的Oracle-SQL指示错误
“未在预期位置找到FROM关键字” ,如下图:
我要运行的代码如下:
select
PCKCOO AS 'COMPANHIA_DO_PEDIDO_NUMERO_DO_PEDIDO',
PCDOCO AS 'DOCUMENTO_NUMERO_DA_OS_FATURA',
PCDCTO AS 'TIPO_DE_ORDEM',
PCSFXO AS 'SUFIXO_DO_PEDIDO',
rpad(HORDT,'0',6) AS 'HORARIO_DE_LIBERACAO',
FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')||' '||rpad(HORDT,6,'0') "APROVACAO",
rank() over (partition by pckcoo, pcdoco, pcdcto, pclnid order by FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')||' '||rpad(HORDT,6,'0') desc) as rank,
FROM PRODDTA.F5543170 a,
proddta.f4209 b,
proddta.f4301 c,
WHERE
PCKCOO = '52171' AND
PCDCTO In ('OP','C1','C2','FZ','OF') AND
((PCTRDJ >= '117060' AND PCTRDJ <= '117090')
or (PCTRDJ >= '116061' AND PCTRDJ <= '116091')
) and
( b.hokcoo = a.pckcoo and
b.hodoco = a.pcdoco and
b.hodcto = a.pcdcto and
B.HOASTS = '2A') and
(c.phkcoo (+)= a.pckcoo and
c.phdoco (+)= COALESCE(TO_NUMBER(REGEXP_SUBSTR(PCOORN, '^(-|+)?d+(.|,)?(d+)?$')), 0) AND
c.phdcto (+)= 'OR')
代码要大得多,但是我将其切成小段,以找出发生这种情况的原因(特别是关于 第3行 和 列:25 如错误消息所示,对我来说这是没有意义的。
另外,当我擦除一些行以更接近错误时,红线(如图所示)保持在第一行。
您是否猜测为什么会这样? (很抱歉再次提出基本问题)。
答案 0 :(得分:2)
proddta.f4301 c
子句的最后一个表(FROM
)中有一个逗号结尾,应该成为
...
FROM PRODDTA.F5543170 a,
proddta.f4209 b,
proddta.f4301 c
...
应将其删除。
select语句中还有一个逗号结尾,也应将其删除。
...
rank() over (partition by pckcoo, pcdoco, pcdcto, pclnid order by FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')||' '||rpad(HORDT,6,'0') desc) as rank
...
最后,对于表别名,您需要使用双引号而不是单引号:
select
PCKCOO AS "COMPANHIA_DO_PEDIDO_NUMERO_DO_PEDIDO",
PCDOCO AS "DOCUMENTO_NUMERO_DA_OS_FATURA",
PCDCTO AS "TIPO_DE_ORDEM",
PCSFXO AS "SUFIXO_DO_PEDIDO",
rpad(HORDT,'0',6) AS "HORARIO_DE_LIBERACAO",
...
答案 1 :(得分:2)
在AS RANK
之后和proddta.f4301 c
之后,您会有一些逗号结尾。
此外,您不能对列别名使用单引号,但需要双引号。 这应该工作:
SELECT PCKCOO AS "COMPANHIA_DO_PEDIDO_NUMERO_DO_PEDIDO",
PCDOCO AS "DOCUMENTO_NUMERO_DA_OS_FATURA",
PCDCTO AS "TIPO_DE_ORDEM",
PCSFXO AS "SUFIXO_DO_PEDIDO",
RPAD(
HORDT,
'0',
6
)
AS "HORARIO_DE_LIBERACAO",
FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')
|| ' '
|| RPAD(
HORDT,
6,
'0'
)
"APROVACAO",
RANK()
OVER(
PARTITION BY pckcoo,
pcdoco,
pcdcto,
pclnid
ORDER BY
FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')
|| ' '
|| RPAD(
HORDT,
6,
'0'
) DESC
)
AS RANK
FROM PRODDTA.F5543170 a,
proddta.f4209 b,
proddta.f4301 c
WHERE PCKCOO = '52171'
AND PCDCTO IN ('OP',
'C1',
'C2',
'FZ',
'OF')
AND ( ( PCTRDJ >= '117060'
AND PCTRDJ <= '117090')
OR ( PCTRDJ >= '116061'
AND PCTRDJ <= '116091'))
AND ( b.hokcoo = a.pckcoo
AND b.hodoco = a.pcdoco
AND b.hodcto = a.pcdcto
AND B.HOASTS = '2A')
AND ( c.phkcoo(+) = a.pckcoo
AND c.phdoco(+) = COALESCE(TO_NUMBER(REGEXP_SUBSTR(PCOORN, '^(-|+)?d+(.|,)?(d+)?$')), 0)
AND c.phdcto(+) = 'OR')
顺便说一句,您最好切换到ANSI JOIN语法。