SlideShare a Scribd company logo
MODUL XI

            PERCABANGAN DAN PERULANGAN PADA PL/SQL



A. Maksud

   Menjelaskan penggunaan perintah-perintah perulangan dan percabangan
   pada PL/SQL.



B. Tujuan

   Mahasiswa dapat menngunakan dan menulis kode PL/SQL dengan
   menggunakan berbagai perintah perulangan dan percabangan sesuai
   dengan kebutuhan.


C. Dasar Teori
Percabangan
Percabangan adalah suatu kontrol untuk pengecekan yang dilakukan sebelum
statemen-statemen dalam sebuah blok PL/SQL dieksekusi.Statement yang
dapat digunakan untuk percabangan adalah IF dan CASE, dengan syntax
sebagai berikut
 IF kondisi THEN Statemen;
 END IF

 CASE (ekspresi)
     WHEN nilai_1 THEN Statemen_1;
     WHEN nilai_2 THEN Statemen_2;
     ………
     WHEN nilai_n THEN Statemen_n
      [ELSE Statemen_lain;]
 END CASE;

Perulangan
Pengulangan adalah suatu blok yang memperbolehkan statemen-statemen
dalam   sebuah    blok   PL/SQL   diulang-ulang.   Tiga   buah   jenis   struktur
pengulangan dalam Oracle, yaitu simple loop, For dan While. Sintak masing-
masing struktur pengulangan tersebut adalah:




                                                                              49
LOOP
      Statement;
      ………
   END LOOP;

   FOR variabel IN indeks_awal .. indeks_akhir LOOP
    Statement;
   …..
   END LOOP

   WHILE kondisi LOOP
      Statemen;
      …………..
   END LOOP;



D. Praktik
Cobalah beberapa PL/SQL dibawah ini
   declare
      noBulan integer;
      namaBulan varchar2(9);
   begin
      noBulan := 3;
      case noBulan
           when 1 then namaBulan := ‘January’;
           when 2 then namaBulan := ‘Februari’;
           when 3 then namaBulan := ‘Maret’;
           when 4 then namaBulan := ‘April’;
           when 5 then namaBulan := ‘Mei’;
           when 6 then namaBulan := ‘Juni’;
           when 7 then namaBulan := ‘Juli’;
           when 8 then namaBulan := ‘Agustus’;
           when 9 then namaBulan := ‘September’;
           when 10 then namaBulan := ‘Oktober’;
           when 11 then namaBulan := ‘November’;
           when 12 then namaBulan := ‘Desember’;
           else namaBulan := ‘’;
   end case;
   dbms_output.put_line(namaBulan);
   end;
   /




   declare

                                                      50
noBulan integer;
    namaBulan varchar2(9);
 begin
    noBulan := 3;
    if noBulan = 1 then
         namaBulan := ‘January’;
    elseif noBulan = 2 then
         namaBulan := ‘Februari’;
    elseif noBulan = 2 then
         namaBulan := ‘Februari’;
    elseif noBulan = 3 then
         namaBulan := ‘Maret’;
    elseif noBulan = 4 then
         namaBulan := ‘April’;
    elseif noBulan = 5 then
         namaBulan := ‘Mei’;
    elseif noBulan = 6 then
         namaBulan := ‘Juni’;
    elseif noBulan = 7 then
         namaBulan := ‘Juli’;
    elseif noBulan = 8 then
         namaBulan := ‘Agustus’;
    elseif noBulan = 9 then
         namaBulan := ‘September’;
    elseif noBulan = 10 then
         namaBulan := ‘Oktober’;
    elseif noBulan = 11 then
         namaBulan := ‘November’;
    elseif noBulan = 12 then
         namaBulan := ‘Desember’;
    else
         namaBulan := ‘’;
    end if;
 dbms_output.put_line(namaBulan);
 end;
 /


declare
    k integer;
begin
    k := 1;
    loop
         dbms_output.put_line(‘Baris ke – ‘||to_char(k));
         k := k+1;
         exit when k > 5;
    end loop;
end;
/

declare

                                                        51
k integer;
 begin
     for k in 1..5 loop
          dbms_output.put_line(‘Baris ke – ‘||to_char(k));
     end loop;
 end;
 /

 declare
     k integer;
 begin
     k := 1;
     while k <= 5 loop
          dbms_output.put_line(‘Baris ke – ‘||to_char(k));
          k := k+1;
     end loop;
 end;
 /


E. Tugas
Akan diberikan pada saat praktikum




                                                         52

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

11 percabangan pl sql

  • 1. MODUL XI PERCABANGAN DAN PERULANGAN PADA PL/SQL A. Maksud Menjelaskan penggunaan perintah-perintah perulangan dan percabangan pada PL/SQL. B. Tujuan Mahasiswa dapat menngunakan dan menulis kode PL/SQL dengan menggunakan berbagai perintah perulangan dan percabangan sesuai dengan kebutuhan. C. Dasar Teori Percabangan Percabangan adalah suatu kontrol untuk pengecekan yang dilakukan sebelum statemen-statemen dalam sebuah blok PL/SQL dieksekusi.Statement yang dapat digunakan untuk percabangan adalah IF dan CASE, dengan syntax sebagai berikut IF kondisi THEN Statemen; END IF CASE (ekspresi) WHEN nilai_1 THEN Statemen_1; WHEN nilai_2 THEN Statemen_2; ……… WHEN nilai_n THEN Statemen_n [ELSE Statemen_lain;] END CASE; Perulangan Pengulangan adalah suatu blok yang memperbolehkan statemen-statemen dalam sebuah blok PL/SQL diulang-ulang. Tiga buah jenis struktur pengulangan dalam Oracle, yaitu simple loop, For dan While. Sintak masing- masing struktur pengulangan tersebut adalah: 49
  • 2. LOOP Statement; ……… END LOOP; FOR variabel IN indeks_awal .. indeks_akhir LOOP Statement; ….. END LOOP WHILE kondisi LOOP Statemen; ………….. END LOOP; D. Praktik Cobalah beberapa PL/SQL dibawah ini declare noBulan integer; namaBulan varchar2(9); begin noBulan := 3; case noBulan when 1 then namaBulan := ‘January’; when 2 then namaBulan := ‘Februari’; when 3 then namaBulan := ‘Maret’; when 4 then namaBulan := ‘April’; when 5 then namaBulan := ‘Mei’; when 6 then namaBulan := ‘Juni’; when 7 then namaBulan := ‘Juli’; when 8 then namaBulan := ‘Agustus’; when 9 then namaBulan := ‘September’; when 10 then namaBulan := ‘Oktober’; when 11 then namaBulan := ‘November’; when 12 then namaBulan := ‘Desember’; else namaBulan := ‘’; end case; dbms_output.put_line(namaBulan); end; / declare 50
  • 3. noBulan integer; namaBulan varchar2(9); begin noBulan := 3; if noBulan = 1 then namaBulan := ‘January’; elseif noBulan = 2 then namaBulan := ‘Februari’; elseif noBulan = 2 then namaBulan := ‘Februari’; elseif noBulan = 3 then namaBulan := ‘Maret’; elseif noBulan = 4 then namaBulan := ‘April’; elseif noBulan = 5 then namaBulan := ‘Mei’; elseif noBulan = 6 then namaBulan := ‘Juni’; elseif noBulan = 7 then namaBulan := ‘Juli’; elseif noBulan = 8 then namaBulan := ‘Agustus’; elseif noBulan = 9 then namaBulan := ‘September’; elseif noBulan = 10 then namaBulan := ‘Oktober’; elseif noBulan = 11 then namaBulan := ‘November’; elseif noBulan = 12 then namaBulan := ‘Desember’; else namaBulan := ‘’; end if; dbms_output.put_line(namaBulan); end; / declare k integer; begin k := 1; loop dbms_output.put_line(‘Baris ke – ‘||to_char(k)); k := k+1; exit when k > 5; end loop; end; / declare 51
  • 4. k integer; begin for k in 1..5 loop dbms_output.put_line(‘Baris ke – ‘||to_char(k)); end loop; end; / declare k integer; begin k := 1; while k <= 5 loop dbms_output.put_line(‘Baris ke – ‘||to_char(k)); k := k+1; end loop; end; / E. Tugas Akan diberikan pada saat praktikum 52