Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ORA-06550: Error in exception and if then else code

Javier PJun 13 2020 — edited Jun 14 2020

Hi,

Am trying to select between two values from two different tables.  If the value of PORC in table RISK_PRODUCTOR is 0 or null

I check the value in PORCIENTO in table RISK_RIESGOS_PRODUCTORES and use that instead if exist.  If not I will assign null.

But am getting this error in this code:

declare

l_porc_productor number;

l_com_productor number;

begin

  select

      nullif(porc,0)

  into

      l_porc_productor

  from

      risk_productor p

  where     

      p.productor_id = :p42_productor_id

      and r.organizacion_id = :APP_GET_ORGANIZACION_ID; 

     exception 

         when no_data_found 

      then 

        l_porc_productor := null;  

 

if l_porc_productor is not null then

       

      :P42_PORC_PRODUCTOR := l_porc_productor; 

 

    else

   

      select 

            nullif(porciento, 0) 

            ,nvl2(nullif(porciento, 0), null, cantidad) 

      into 

           :p42_PORC_PRODUCTOR 

           ,:p42_COM_PRODUCTOR 

      from 

          risk_riesgos_productores r 

      where 

          r.agencia_id = :p42_agencia_id 

          and r.compania_id = :p42_compania_id 

          and r.riesgo_id = :p42_riesgo_id

          and r.productor_id = :p42_productor_id

          and nvl(:P42_PORC_PRODUCTOR,'0') = 0

          and r.organizacion_id = :APP_GET_ORGANIZACION_ID; 

ORA-06550: line 43, column 6: PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: ( begin case declare end exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge json_exists json_value json_query json_object json_array

     exception 

         when no_data_found 

      then 

        :p42_porc_productor := null; 

        :p42_com_productor := null; 

end if;

end;

What am missing here?

Thanks for any help!!!

This post has been answered by mathguy on Jun 14 2020
Jump to Answer

Comments

Processing

Post Details

Added on Jun 13 2020
7 comments
1,365 views