PL/SQL Use the Case Statement


create table students
(
  student_id number not null,
  student_name varchar2(50),
  student_surname varchar2(50) not null,
  section_id number,
  final_grade number,
  letter_grade char(1),
  constraint students_pk primary key(student_id)
);

insert into students
values
(
  1,
  'Nurhak',
  'Kaya',
  89,
  85,
  'D'
);

declare
  v_student_id number:=1;
  v_section_id number:=89;
  v_final_grade number;
  v_letter_grade char(1);
begin
  select final_grade
  into v_final_grade
  from students
  where student_id=v_student_id
  and section_id=v_section_id;
 
  case
      when v_final_grade>=90 then v_letter_grade:='A';
      when v_final_grade>=80 then v_letter_grade:='B';
      when v_final_grade>=70 then v_letter_grade:='C';
      when v_final_grade>=60 then v_letter_grade:='D';
      else v_letter_grade:='F';
    end case;
    --check result
    dbms_output.put_line('Exam result is: '||v_letter_grade);
end;

declare

  v_date date:=to_date('&sv_user_date','DD-MON-YYYY');
  v_day varchar2(1);
begin
  v_day := to_char(v_date,'D');
  case v_day
      when '1' then dbms_output.put_line('Sunday');
      when '2' then dbms_output.put_line('Monday');
      when '3' then dbms_output.put_line('Tuesday');
      when '4' then dbms_output.put_line('Wednesday');
      when '5' then dbms_output.put_line('Thursday');
      when '6' then dbms_output.put_line('Friday');
      when '7' then dbms_output.put_line('Saturday');
    end case;
end;

Comments

Popular posts from this blog

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Solution for "Can not obtain Oracle client information from registry"