问题
Sorry for my noob question but I'm trying to figure out why my Oracle-SQL indicates the error
"FROM keyword not found where expected" as the picture below:
The code I'm trying to run is the following:
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')
The code was a lot bigger but I cut it into pieces in order to find out why this is happening (specially regarding the Line: 3 and Column: 25 as the error message indicated, which for me makes no sense).
Additionally, when I erase some lines in order to get closer towards the error, the red line (as indicated in the picture) keeps in the first line.
Do you have a guess of why this is happening? (sorry for the basic question again).
回答1:
You have a trailing comma in the last table (proddta.f4301 c) of FROM clause and should become
...
FROM PRODDTA.F5543170 a,
proddta.f4209 b,
proddta.f4301 c
...
which should be removed.
You also have a trailing comma in your select statement that should also be removed.
...
rank() over (partition by pckcoo, pcdoco, pcdcto, pclnid order by FX_PARA_GREGORIANA(HORDJ, 'DD/MM/YYYY')||' '||rpad(HORDT,6,'0') desc) as rank
...
Finally, for table alias you need to use double instead of single quotes:
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",
...
回答2:
You have some trailing commas after AS RANK and after proddta.f4301 c.
Also, you can not use single quotes for column aliases, but you need double quotes; this should work:
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')
As an aside, you should better switch to ANSI JOIN syntax.
来源:https://stackoverflow.com/questions/52278020/oracle-sql-developer-error-from-keyword-not-found-where-expected