Oracle: Control statement IF. elsif statement, Case statement, for Loop statement

Source: Internet
Author: User
Tags case statement

--Multiple IF statements ( note: BEGIN END, IF condition then,elsif condition Then,else ... END IF )
begin
if FALSE then
Dbms_output.put_line (' Execute if statement ... ');
elsif   True then
Dbms_output.put_line (' Execute ELEIF1 statement ... ');
elsif   TRUE then
Dbms_output.put_line (' Execute ELEIF2 statement ... ');
elsif   FALSE then
Dbms_output.put_line (' Execute ELEIF3 statement ... ');
end IF;
end;

--percentile results converted to five points and printed output
DECLARE
V_score Number (3): = ' &score ';
BEGIN
  IF v_score>90 Then
Dbms_output.put_line (' A ');
  elsif v_score>80 Then
Dbms_output.put_line (' B ');
  elsif v_score>70 Then
Dbms_output.put_line (' C ');
  elsif v_score>60 Then
Dbms_output.put_line (' D ');
  ELSE
Dbms_output.put_line (' E ');
  END IF;
END;

--case Demonstration ( Note: BEGIN end,case subject, when condition then,else...,endcase)
DECLARE
V_light VARCHAR2 (Ten): = ' &light ';
BEGIN
   Case V_light
   when ' Red light ' then
Dbms_output.put_line (' Stop ');
   when ' Green light ' then
Dbms_output.put_line (' line ');
   when ' Yellow light ' Then
Dbms_output.put_line (' et ');
  ELSE
Dbms_output.put_line (' The information you entered is incorrect. ‘);
  END case;
END;

--for Loop ( Note: BEGIN end,loop. EXIT when TRUE: END LOOP)
BEGIN
  LOOP
Dbms_output.put_line (' information ... ');
  EXIT when TRUE;
  END LOOP;
END;

--Let the above loop execute 5 times
DECLARE
V_i Number (10): = 0;
BEGIN
  LOOP
Dbms_output.put_line (' information ... ');
V_i: = v_i + 1;
  EXIT when v_i=5;
  END LOOP;
END;

Oracle: Control statement IF. elsif statement, Case statement, for Loop statement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.