PLS-00103: Encountered the symbol “EXCEPTION” error while checking for a value in the bind variable

StackOverflow https://stackoverflow.com/questions/8458716

  •  13-03-2021
  •  | 
  •  

Question

I am getting the below error for the PL/SQL block I executed.

ORA-06550: line 16, column 1: PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:

My anonymous procedure below was working fine until I included the user defined exception e_nonrented. Which checks if the value of bindvariable :g_movie_id=2.. If that is the case it throws an exception...

Below is the code:

VARIABLE g_movie_id NUMBER EXEC :g_movie_id := 2
DECLARE v_count NUMBER;
v_movieid NUMBER;
v_title mm_movie.movie_title%TYPE;
e_nonrented

 EXCEPTION;
BEGIN
  SELECT m.movie_title,
    COUNT(r.rental_id),
    r.movie_id
  INTO v_title,
    v_count,
    v_movieid
  FROM mm_movie m,
    mm_rental r
  WHERE m.movie_id = r.movie_id
   AND m.movie_id = :g_movie_id
  GROUP BY m.movie_title,
    r.movie_id;
  DBMS_OUTPUT.PUT_LINE(v_title || ': ' || v_count);

  IF :g_movie_id = 2 THEN
    RAISE e_nonrented;

  EXCEPTION
  WHEN no_data_found THEN
    DBMS_OUTPUT.PUT_LINE('there is no movie id for: ' || :g_movie_id);
  WHEN e_nonrented THEN
    DBMS_OUTPUT.PUT_LINE(' Movie with Id ');
  END;
Was it helpful?

Solution

You're simply missing an END IF; statement.

  IF :g_movie_id = 2 THEN
    RAISE e_nonrented;
  END IF;

EXCEPTION
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top