Home » SQL & PL/SQL » SQL & PL/SQL » PL/SQL error (Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit)
PL/SQL error [message #653525] Sat, 09 July 2016 13:51 Go to next message
jcasas
Messages: 5
Registered: November 2006
Location: MEXICO
Junior Member
I'm facing this error message PL/SQL: ORA-00923: FROM keyword not found where expected on my query, I did review and could not find what is happening.

This is my query
select JOBTITLE,promotion_id,
nombre ,DATE_PASSED,
case when instr(cursos,id_curso) > 0 then 1 else 0 end aprobado from (
select distinct a.id_motores_oem , a.motor, c.sp_code from ZMKT7352_MOTORES_OEM a
inner join ZMKT7352_OEM b on a.oem = to_char(b.id_oem)
inner join ZMKT7352_DR_DEALERS_EBU c on b.id_oem = c.MEXICO_EQUIVALENT_OEM
inner join ZMKT7352_MOTORES d
on d.id_motores = a.id_motores_oem
full outer join ZMKT7352_REL_PERFIL_MOTOR e
on e.id_motor = a.id_motores_oem
and c.sp_code = e.sp_code
where c.sp_code = p_code and e.id_motor is not null
) a inner join ZMKT7352_REL_MOTOR_HEADER f
on f.ID_MOTOR = a.id_motores_oem
inner join ZMKT7352_REL_MOTOR_CURSOS g
on f.id_header = g.id_header
full outer join
(select promotion_id, DATE_PASSED, FIRST_NAME||' ' ||LAST_NAME as nombre , LISTAGG(PROGRAM_ID, ',') WITHIN GROUP (ORDER BY PROGRAM_ID) as cursos, sp_code,JOBTITLE from ZMKT7352_PROMOTION
where sp_code = p_code
group by FIRST_NAME,LAST_NAME,sp_code,JOBTITLE,DATE_PASSED,promotion_id) h
on h.sp_code = a.sp_code
where PUESTO = 1
order by motor )
)group by promotion_id, JOBTITLE, nombre, DATE_PASSED
having sum(aprobado) =1 or JOBTITLE in( 'Warranty')
order by nombre;

DB Version
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Re: PL/SQL error [message #653526 is a reply to message #653525] Sat, 09 July 2016 14:10 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read our OraFAQ Forum Guide and please read How to use [code] tags and make your code easier to read

which line is reported as the problem?

SELECT          jobtitle, 
                promotion_id, 
                nombre , 
                date_passed, 
                CASE 
                                WHEN Instr(cursos,id_curso) > 0 THEN 1 
                                ELSE 0 
                END aprobado 
FROM            ( 
                                SELECT DISTINCT a.id_motores_oem , 
                                                a.motor, 
                                                c.sp_code 
                                FROM            zmkt7352_motores_oem a 
                                inner join      zmkt7352_oem b 
                                ON              a.oem = To_char(b.id_oem) 
                                inner join      zmkt7352_dr_dealers_ebu c 
                                ON              b.id_oem = c.mexico_equivalent_oem 
                                inner join      zmkt7352_motores d 
                                ON              d.id_motores = a.id_motores_oem 
                                full outer join zmkt7352_rel_perfil_motor e 
                                ON              e.id_motor = a.id_motores_oem 
                                AND             c.sp_code = e.sp_code 
                                WHERE           c.sp_code = p_code 
                                AND             e.id_motor IS NOT NULL ) a 
inner join      zmkt7352_rel_motor_header f 
ON              f.id_motor = a.id_motores_oem 
inner join      zmkt7352_rel_motor_cursos g 
ON              f.id_header = g.id_header 
full outer join 
                ( 
                         SELECT   promotion_id, 
                                  date_passed, 
                                  first_name 
                                           ||' ' 
                                           ||last_name                                        AS nombre ,
                                  Listagg(program_id, ',') within GROUP (ORDER BY program_id) AS cursos,
                                  sp_code, 
                                  jobtitle 
                         FROM     zmkt7352_promotion 
                         WHERE    sp_code = p_code 
                         GROUP BY first_name, 
                                  last_name, 
                                  sp_code, 
                                  jobtitle, 
                                  date_passed, 
                                  promotion_id) h 
ON              h.sp_code = a.sp_code 
WHERE           puesto = 1 
ORDER BY        motor ) )GROUP BY promotion_id, jobtitle, nombre, date_passed HAVING SUM(aprobado) =1
OR 
jobtitle IN( 'Warranty') ORDER BY nombre;
Re: PL/SQL error [message #653527 is a reply to message #653525] Sat, 09 July 2016 14:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

You can use SQL Formatter to help you.

SQL>  SELECT          jobtitle,
  2                  promotion_id,
  3                  nombre ,
  4                  date_passed,
  5                  CASE
  6                                  WHEN Instr(cursos,id_curso) > 0 THEN 1
  7                                  ELSE 0
  8                  END aprobado
  9  FROM            (
 10                                  SELECT DISTINCT a.id_motores_oem ,
 11                                                  a.motor,
 12                                                  c.sp_code
 13                                  FROM            zmkt7352_motores_oem a
 14                                  INNER JOIN      zmkt7352_oem b
 15                                  ON              a.oem = To_char(b.id_oem)
 16                                  INNER JOIN      zmkt7352_dr_dealers_ebu c
 17                                  ON              b.id_oem = c.mexico_equivalent_oem
 18                                  INNER JOIN      zmkt7352_motores d
 19                                  ON              d.id_motores = a.id_motores_oem
 20                                  FULL OUTER JOIN zmkt7352_rel_perfil_motor e
 21                                  ON              e.id_motor = a.id_motores_oem
 22                                  AND             c.sp_code = e.sp_code
 23                                  WHERE           c.sp_code = p_code
 24                                  AND             e.id_motor IS NOT NULL ) a
 25  INNER JOIN      zmkt7352_rel_motor_header f
 26  ON              f.id_motor = a.id_motores_oem
 27  INNER JOIN      zmkt7352_rel_motor_cursos g
 28  ON              f.id_header = g.id_header
 29  FULL OUTER JOIN
 30                  (
 31                           SELECT   promotion_id,
 32                                    date_passed,
 33                                    first_name
 34                                             ||' '
 35                                             ||last_name                                        AS nombre ,
 36                                    Listagg(program_id, ',') within GROUP (ORDER BY program_id) AS cursos,
 37                                    sp_code,
 38                                    jobtitle
 39                           FROM     zmkt7352_promotion
 40                           WHERE    sp_code = p_code
 41                           GROUP BY first_name,
 42                                    last_name,
 43                                    sp_code,
 44                                    jobtitle,
 45                                    date_passed,
 46                                    promotion_id) h
 47  ON              h.sp_code = a.sp_code
 48  WHERE           puesto = 1
 49  ORDER BY        motor ) )GROUP BY promotion_id, jobtitle, nombre, date_passed HAVING sum(aprobado) =1
 50  OR
 51  jobtitle IN( 'Warranty')
 52  ORDER BY nombre;
ORDER BY        motor ) )GROUP BY promotion_id, jobtitle, nombre, date_passed HAVING sum(aprobado) =1
                      *
ERROR at line 49:
ORA-00933: SQL command not properly ended
I don't know what you want to do but syntactically the query ends where SQL*Plus marks the error, that is what is after the ORDER BY clause is out of the query.

Maybe this is what you wanted to do?
SELECT jobtitle,
       promotion_id,
       nombre,
       date_passed,
       CASE
         WHEN Instr(cursos, id_curso) > 0 THEN 1
         ELSE 0
       END aprobado
FROM   (SELECT DISTINCT a.id_motores_oem,
                        a.motor,
                        c.sp_code
        FROM   zmkt7352_motores_oem a
               inner join zmkt7352_oem b
                       ON a.oem = To_char(b.id_oem)
               inner join zmkt7352_dr_dealers_ebu c
                       ON b.id_oem = c.mexico_equivalent_oem
               inner join zmkt7352_motores d
                       ON d.id_motores = a.id_motores_oem
               full outer join zmkt7352_rel_perfil_motor e
                            ON e.id_motor = a.id_motores_oem
                               AND c.sp_code = e.sp_code
        WHERE  c.sp_code = p_code
               AND e.id_motor IS NOT NULL) a
       inner join zmkt7352_rel_motor_header f
               ON f.id_motor = a.id_motores_oem
       inner join zmkt7352_rel_motor_cursos g
               ON f.id_header = g.id_header
       full outer join (SELECT promotion_id,
                               date_passed,
                               first_name
                               ||' '
                               ||last_name                          AS nombre,
                               Listagg(program_id, ',')
                                 within GROUP (ORDER BY program_id) AS cursos,
                               sp_code,
                               jobtitle
                        FROM   zmkt7352_promotion
                        WHERE  sp_code = p_code
                        GROUP  BY first_name,
                                  last_name,
                                  sp_code,
                                  jobtitle,
                                  date_passed,
                                  promotion_id) h
                    ON h.sp_code = a.sp_code
WHERE  puesto = 1
GROUP  BY promotion_id,
          jobtitle,
          nombre,
          date_passed
HAVING SUM(aprobado) = 1
        OR jobtitle IN( 'Warranty' )
ORDER  BY nombre
/
Re: PL/SQL error [message #653529 is a reply to message #653526] Sat, 09 July 2016 14:26 Go to previous messageGo to next message
jcasas
Messages: 5
Registered: November 2006
Location: MEXICO
Junior Member
Thanks for your clarification on how to present queries, I did rewrite and here is complete

select  promotion_id id_promos,  
        nombre,
        JOBTITLE motor, 
        DATE_PASSED, 
        100 posible ,
        sum(aprobado)*100 Porcentaje  
from (
        select  distinct promotion_id, 
                JOBTITLE,
                nombre ,
                DATE_PASSED, 
                aprobado 
        from (  
                 select JOBTITLE,
                        promotion_id,
                        nombre ,
                        DATE_PASSED,
                        case 
                                when instr(cursos,id_curso) > 0 then 1 
                                else 0 
                        end aprobado 
                 from (
                        select distinct  a.id_motores_oem , --****ERROR IS MARKED IN THIS LINE*****
                                         a.motor, 
                                         c.sp_code 
                        from            ZMKT7352_MOTORES_OEM a
                        inner join      ZMKT7352_OEM b 
                        on              a.oem = to_char(b.id_oem)
                        inner join      ZMKT7352_DR_DEALERS_EBU c 
                        on              b.id_oem = c.MEXICO_EQUIVALENT_OEM
                        inner join      ZMKT7352_MOTORES d
                        on              d.id_motores = a.id_motores_oem
                        full outer join ZMKT7352_REL_PERFIL_MOTOR e
                        on              e.id_motor =  a.id_motores_oem
                        and             c.sp_code = e.sp_code
                        where           c.sp_code = p_code 
                        and             e.id_motor is not null) a 
                 inner join ZMKT7352_REL_MOTOR_HEADER f
                 on         f.ID_MOTOR = a.id_motores_oem
                 inner join ZMKT7352_REL_MOTOR_CURSOS g
                 on         f.id_header = g.id_header
                 full outer join
                        (
                            select      promotion_id, 
                                        DATE_PASSED, 
                                        FIRST_NAME
                                        ||' ' 
                                        ||LAST_NAME                                                 as nombre , 
                                        Listagg(program_id, ',') within GROUP (ORDER BY program_id) AS cursos, 
                                        sp_code,
                                        JOBTITLE 
                            from        ZMKT7352_PROMOTION
                            where       sp_code = p_code
                            group by    FIRST_NAME,
                                        LAST_NAME,
                                        sp_code,
                                        JOBTITLE,
                                        DATE_PASSED,
                                        promotion_id) h
                on h.sp_code = a.sp_code
                where PUESTO = 1
                order by motor  ) )     group by promotion_id, JOBTITLE, nombre, DATE_PASSED having sum(aprobado) =1 
                or 
                JOBTITLE in( 'Warranty') order by nombre;

The error does not make me any sense, I have 3 similar error inside my package once I compile it, and other 2 are highlighted in 2 lines that there is no any code there. I'm using TOAD.

Thanks for your help

[Updated on: Sat, 09 July 2016 14:46]

Report message to a moderator

Re: PL/SQL error [message #653530 is a reply to message #653529] Sat, 09 July 2016 15:07 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Saying that you have similar errors when compiling a package, don't you think that you should have posted the package (body) and specify lines that throw those errors? Maybe the query itself looks OK, but - in PL/SQL environment - lacks in something that prevents it from being correct.

(For MC: no, TOAD is not what you usually call it; it is a victim here) /forum/fa/1626/0/
Re: PL/SQL error [message #653531 is a reply to message #653530] Sat, 09 July 2016 15:28 Go to previous messageGo to next message
jcasas
Messages: 5
Registered: November 2006
Location: MEXICO
Junior Member
Thanks for your recommendation here is the complete package body
A lot of code here


[EDITED by LF: applied [spoiler] tags to visually shorten the message]

[Updated on: Sat, 09 July 2016 16:34] by Moderator

Report message to a moderator

Re: PL/SQL error [message #653532 is a reply to message #653531] Sat, 09 July 2016 16:37 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
That's a lot of code. You didn't specify which lines raise the error; could you do that, please? (Basically, you'd copy/paste TOAD's or SQL*Plus' error stack over here).
Re: PL/SQL error [message #653534 is a reply to message #653532] Sat, 09 July 2016 17:55 Go to previous messageGo to next message
jcasas
Messages: 5
Registered: November 2006
Location: MEXICO
Junior Member
Thanks Littlefoot, I did highlighted the line error with ***** ERROR IS MARKED IN THIS LINE****** before your reply. I just include only the query where the error appears.

Re: PL/SQL error [message #653535 is a reply to message #653534] Sat, 09 July 2016 18:11 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Realize that since we don't have your tables we can't run your code or even get close to compiling it.
I suspect that SQL is missing one or more ")"; but is hard to know for sure based only upon visual desk checking.
Re: PL/SQL error [message #653537 is a reply to message #653535] Sat, 09 July 2016 20:11 Go to previous messageGo to next message
jcasas
Messages: 5
Registered: November 2006
Location: MEXICO
Junior Member
Dear Blacksawn

I did think that too, but I review the structure several times and still do not find which special character is missing, I have this same pkg body in my DEV environment and it is working properly, I do not have a clue why in my staging environment is appearing this error.

Thanks
Re: PL/SQL error [message #653538 is a reply to message #653537] Sat, 09 July 2016 20:23 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
jcasas wrote on Sat, 09 July 2016 18:11
Dear Blacksawn

I did think that too, but I review the structure several times and still do not find which special character is missing, I have this same pkg body in my DEV environment and it is working properly, I do not have a clue why in my staging environment is appearing this error.

Thanks


Something is different.
Your challenge is to find it.
Re: PL/SQL error [message #653539 is a reply to message #653537] Sat, 09 July 2016 21:09 Go to previous message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
The code that you originally posted had a mismatched number of left and right parentheses and various other errors concerning usage of sum and group by and having. The rewrite that you posted fixed those things. The package seems to contain various similar versions of such queries for which ref cursors are opened. You need to make sure you are running what you think you are running and not some prior version. You then need to narrow down the problem by testing things individually. If the problem appears to be in one select statement from one procedure, then run that select statement by itself, outside of the procedure, from SQL*Plus. If you get an error, then start by running just the innermost sub-query by itself. If that runs correctly, then add the next level of sub-query until you determine where the problem is. Sometimes error messages can seem somewhat misleading until you get used to how Oracle looks at things. Frequently, there may be something wrong with the line above or below that causes it to expect something different on the next or preceding line. Another thing that you could try is if your packages or queries are identical and are supposed to be that way, then copy the one that works and overwrite the one that doesn't. If it still doesn't work, then there is something different in the environments. If you can post a describe of each of your tables, then we can use that to test your code. If you can post a copy and paste of an actual run of just the problem select statement outside of the procedure and the resulting error, run from SQL*Plus, so that it shows line numbers and does not mask any errors, then we may also be able to provide further help.
Previous Topic: Oracle reports
Next Topic: information
Goto Forum:
  


Current Time: Fri Apr 26 08:46:11 CDT 2024