1

I was writing a simple program of senior citizen checking. But the error baffled me. The code as follows

declare
  gen char(1);
    age number(3);

begin
  gen:='&gen';
    age:=&age;

  if age>65 and gen='m'
    then
      dbms_output.put_line("senior citizen");

  elsif age>60 and gen='f'
    then
      dbms_output.put_line("senior citizen");

  else
      dbms_output.put_line(" not a senior citizen");
  endif;
end;

error at line 20:
ora 06550:line 20, column 4
pls-00103:encountered symbol ';' when expecting one of the following if

I really don't know what is wrong

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Swayambhu
  • 458
  • 2
  • 8
  • 19

3 Answers3

3
declare
  gen char(1);
    age number(3);

begin
  gen:='&gen';
    age:=&age;

  if age>65 and gen='m'
    then
      dbms_output.put_line('senior citizen');

  elsif age>60 and gen='f'
    then
      dbms_output.put_line('senior citizen');

  else
      dbms_output.put_line(' not a senior citizen');
  end if;
end;

You have to use ' instade of " to show string messages when using dbms_output.put_line
Also there was an endif ,that must be replace with end if
Hope be helpful pal.

Mohsen Heydari
  • 7,256
  • 4
  • 31
  • 46
1

It should be "end if;", not "endif;".

(And yes, this is somewhat inconsistent with "elsif". Funny old thing, syntax... :-)

Share and enjoy.

0
declare
    gen char(1)   := lower(:Gender)   ;
    age number(3) := :Age;
begin

  if ( 
    (age>65 and gen = 'm') OR (age>60 and gen ='f')
  )then
    dbms_output.put_line('senior citizen');
  else
    dbms_output.put_line(' not a senior citizen');
end if;
end;
benka
  • 4,732
  • 35
  • 47
  • 58
AleRV
  • 11
  • 2
  • It would be helpful if you tell what exactly you changed in the code to make it work. For a feature visitor it is not helpful that they have to compare the original code with your code to guess what they should do with their code to fix a similar problem. – Sumurai8 Jul 19 '14 at 17:56