on a pl / sql exercise

0
CREATE OR REPLACE PROCEDURE orden (n1 IN OUT number, n2 IN OUT number, n3 IN OUT number) AS
    menor number;
    mediano number;
    mayor number;
BEGIN
    IF n1 < n2 THEN
        IF n2 < n3 THEN
            mediano := n2;
            mayor   := n3;
            IF n1 < n3 THEN
                menor := n1;
            END IF;
        ELSE
            mediano := n3;
            mayor   := n2;
        END IF;
    ELSE
        menor := n3;
        mediano := n1;
        mayor := n2;    
    END IF;
    ELSE
        IF n1 < n3 THEN
            menor := n3;
            mediano := n1;
            mayor := n2;
        END IF;
    ELSE
        mayor := n1;
        IF n2 < n3 THEN
            mediano := n2;
            menor := n1;
        END IF;
    ELSE
        mediano := n2;
        menor   := n1;

    END IF;
    n1 := menor;
    n2 := mediano;
    n3 := mayor;    
END;
/

and he tells me that I have an error in the following lines:

  

22/1 PLS-00103: Encountered the symbol "ELSE" when expecting one of
  The following: (begin case declare end exception exit for goto if   loop mod null pragma raise return select update while with   < < continue close current delete fetch lock insert open rollback   savepoint set sql execute commit forall merge pipe purge

     

28/1 PLS-00103: Encountered the symbol "ELSE" when expecting one of
  the following:

     

LINE / COL ERROR   -------- ------------------------------------------ ----------------------- (begin case declare end exit for goto if loop mod null pragma raise   return select update while with < < continue close current   delete fetch lock insert open rollback savepoint set sql execute   commit forall merge pipe purge

     

34/1 PLS-00103: Encountered the symbol "ELSE" when expecting one of
  The following: (begin case declare end exit for goto if loop mod   null pragma raise return select update while with     < < <

     

LINE / COL ERROR   -------- ------------------------------------------ ----------------------- continue close current delete fetch lock insert open rollback
  savepoint set sql execute commit forall merge pipe purge

     

39/1 PLS-00103: Encountered the symbol "N1" 42/4 PLS-00103:   Encountered the symbol "end-of-file" when expecting one of the   following: end not pragma final instantiable order overriding static      member constructor map

    
asked by jessica 16.04.2017 в 12:25
source

1 answer

0

As your error indicates, you are doing wrong to close the condition. Specifically in the EndIF of line 21 you are closing the condition of

  IF n1 < n2 THEN

That is why the ELSE of line 22 returns an error, as it does not have a conditional to associate with.

From that line, you have several "ELSE" that do not hang on any condition. Several points to keep in mind here:

1: That is incorrect, the "ELSE" is made to cover all cases that have not been covered in the previous conditions. Instead, use the elsif (condition) statement. Leaving a single else for the generic case that does not comply with the exposed conditions.

2: Facing a larger code, the basic structure for creating conditionals is as follows

if (condicion1) then
-- Lo que sea
elsif (condicion2) then
-- lo que sea si se cumple la condición
elsif (condicionN) then
-- lo que sea si se cumple
else -- sin condicion
-- Caso si no es ninguno de los anteriores
end if;

Greetings

    
answered by 16.04.2017 в 12:39