tag:blogger.com,1999:blog-27379766247190604452024-02-08T12:52:35.835-08:00About my life ^_^about my life ^_^http://www.blogger.com/profile/03212278237422880307noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-2737976624719060445.post-18436893982404245252010-11-17T05:09:00.000-08:002010-11-17T05:09:11.678-08:00Belajar Menulis dan Membaca Part 4 [Cursor Eksplisit dan Implisit]<span style="color: purple; font-family: Arial,Helvetica,sans-serif; font-size: small;">CURSOR</span><br />
<br />
<span style="font-family: Arial,Helvetica,sans-serif;">Cursor merupakan sejenis variabel yang dapat digunakan untuk menampung banyak nilai berupa baris atau record. dapat dikatakan pula kursor adalah pointer yang menunjuk ke suatu bagian memori untuk menyimpan hasil intruksi SQL. hasil intruksi tersebut biasanya merupakan multiple row, dan kursor digunakan untuk menunjuk pointer ke salah satu baris. Kursor terdiri dari 2 macam, yaitu kursor implisit dan eksplisit. </span><br />
<br />
<span style="color: red; font-family: Arial,Helvetica,sans-serif;">1. Cursor Implisit </span><br />
<span style="color: red; font-family: Arial,Helvetica,sans-serif;"> <span style="color: black;">cursor implisit merupakan cursor yang tidak perlu di deklarasikan sebelumnya. cursor ini berasosiasi dengan perintah SELECT, INSERT, DELETE, dan UPDATE.</span></span><br />
<br />
<div style="color: blue;"><span style="color: blue; font-family: Arial,Helvetica,sans-serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;">contoh koding yang menggunakan</span></span> </span><span style="font-family: "Courier New",Courier,monospace; font-size: x-small;">cursor implisit</span></div> <b> <span style="font-family: "Courier New",Courier,monospace;">contoh 1:</span></b><br />
<br />
<div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> declare</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> nama_cari</span><span style="color: black;"> </span><span style="color: black;">varchar</span><span style="color: black;">(15);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> nama_depan</span><span style="color: black;"> </span><span style="color: black;">varchar</span><span style="color: black;">(15);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> nama_belakang</span><span style="color: black;"> </span><span style="color: black;">varchar</span><span style="color: black;">(15);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> gaji</span><span style="color: black;"> </span><span style="color: black;">varchar</span><span style="color: black;">(10);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> begin</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> nama_cari</span><span style="color: black;"> := '&</span><span style="color: black;">masukkan_nama</span><span style="color: black;">';</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> select </span><span style="color: black;">first_name</span><span style="color: black;">, </span><span style="color: black;">last_name</span><span style="color: black;">, salary</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> into </span><span style="color: black;">nama_depan</span><span style="color: black;">, </span><span style="color: black;">nama_belakang</span><span style="color: black;">, </span><span style="color: black;">gaji</span><span style="color: black;"> </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> from employees</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> where </span><span style="color: black;">first_name</span><span style="color: black;"> = </span><span style="color: black;">nama_cari</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> dbms_output.put_line</span><span style="color: black;">('</span><span style="color: black;">pegawai</span><span style="color: black;"> </span><span style="color: black;">bernama</span><span style="color: black;"> '||</span><span style="color: black;">nama_depan</span><span style="color: black;">||’ ‘ ||</span><span style="color: black;">nama_belakang</span><span style="color: black;">||' </span><span style="color: black;">gajinya</span><span style="color: black;"> </span><span style="color: black;">adalah</span><span style="color: black;"> USD '||</span><span style="color: black;">gaji</span><span style="color: black;">);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> end;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> /</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><b><i><span style="font-size: x-small;"><span style="color: black;"> </span></span></i><span style="font-size: x-small;"><span style="color: black;">contoh 2:</span></span></b></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black;"> </span></span><i><span style="font-size: x-small;"><span style="color: black;"> declare</span></span></i><i><span style="font-size: x-small;"><span style="color: black;"> </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.56pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> nama_cari</span><span style="color: black;"> </span><span style="color: black;">employees.first_name%type</span><span style="color: black;"></span></span></i><i><span style="font-size: x-small;"><span style="color: black;">nama_depan</span><span style="color: black;"> </span><span style="color: black;">employees.first_name%type</span><span style="color: black;">;</span></span></i> </div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> alamat_email</span><span style="color: black;"> </span><span style="color: black;">employees.email%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> telepon</span><span style="color: black;"> </span><span style="color: black;">employees.phone_number%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> begin</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> nama_cari</span><span style="color: black;"> := '&</span><span style="color: black;">masukkan_nama</span><span style="color: black;">';</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> select </span><span style="color: black;">first_name</span><span style="color: black;">, email, </span><span style="color: black;">phone_number</span><span style="color: black;"> </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> into </span><span style="color: black;">nama_depan</span><span style="color: black;">, </span><span style="color: black;">alamat_email</span><span style="color: black;">, </span><span style="color: black;">telepon</span><span style="color: black;"> </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> from employees</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> where </span><span style="color: black;">first_name</span><span style="color: black;"> = </span><span style="color: black;">nama_cari</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> dbms_output.put_line</span><span style="color: black;">('</span><span style="color: black;">Nama</span><span style="color: black;">: '||</span><span style="color: black;">nama_depan</span><span style="color: black;">); </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> dbms_output.put_line</span><span style="color: black;">('Email: '||</span><span style="color: black;">alamat_email</span><span style="color: black;">||'@</span><span style="color: black;">SemogaJaya.co.id</span><span style="color: black;">');</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> dbms_output.put_line</span><span style="color: black;">('</span><span style="color: black;">Telepon</span><span style="color: black;">: '||</span><span style="color: black;">telepon</span><span style="color: black;">);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> end;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"> /</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black;"><span style="color: red;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;">2. Cursor Eksplisit</span></span></span></span></span></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black;"><span style="color: red;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"> Cursor eksplisit merupakan cursor yang harus dibuka dan ditutup secara manual. </span></span></span></span></span></span></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black;"><span style="color: red;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"> </span></span></span></span></span></span> </div><div style="color: red; direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: center; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="font-weight: bold;">DOFC </span><span style="font-weight: bold;"></span><span style="font-weight: bold;"> (DECLARE, OPEN, FETCH, CLOSE)</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="color: black; font-family: Arial; font-size: 17pt;"> </span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">Declare</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">cursor <span style="color: red;">[</span></span><span style="color: red; font-family: Arial;">nama_cursor_bebas</span><span style="color: black; font-family: Arial;"><span style="color: red;">]</span> is</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">select <span style="color: #b45f06;">[</span></span><span style="color: #b45f06; font-family: Arial;">daftar_kolom]</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">from <span style="color: magenta;">[</span></span><span style="color: magenta; font-family: Arial;">daftar_tabel]</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">where <span style="color: lime;">[</span></span><span style="color: lime; font-family: Arial;">syarat];</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">begin</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">open <span style="color: red;">[</span></span><span style="color: red; font-family: Arial;">nama_cursor_bebas</span><span style="color: black; font-family: Arial;"><span style="color: red;">]</span>;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">loop</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;"><span> </span>fetch [</span><span style="color: red; font-family: Arial;">nama_cursor_bebas</span><span style="color: black; font-family: Arial;"><span style="color: red;">]</span> into <span style="color: #351c75;">[</span></span><span style="color: #351c75; font-family: Arial;">daftar_variabel</span><span style="color: black; font-family: Arial;"><span style="color: #351c75;">]</span>;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;"><span> </span>exit when <span style="color: red;">[</span></span><span style="color: red; font-family: Arial;">nama_cursor_bebas</span><span style="color: black; font-family: Arial;"><span style="color: red;">]</span> %</span><span style="color: black; font-family: Arial;">notfound</span><span style="color: black; font-family: Arial;">;</span></span></i></div><div style="color: #f1c232; direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="font-family: Arial;"><span> </span></span><span style="font-family: Arial; font-style: italic;">[</span><span style="font-family: Arial; font-style: italic;">aksi_lain</span><span style="font-family: Arial; font-style: italic;">]</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">end loop;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">close <span style="color: red;">[</span></span><span style="color: red; font-family: Arial;">nama_cursor_bebas</span><span style="color: black; font-family: Arial;"><span style="color: red;">]</span>;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">end;</span></span></i></div><i><span style="font-size: small;"><span style="color: black; font-family: Arial;">/</span></span></i><span style="font-size: x-small;"><span style="color: black;"><span style="color: red;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"> </span></span></span></span></span></span><br />
<div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="color: blue; direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-family: "Courier New",Courier,monospace;">contoh kodingan cursor eksplisit</span></span></span></span></div><div style="color: blue; direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><b><span style="font-size: x-small;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: black;">contoh 1:</span></span></span></span></span></b></div><div style="color: blue; direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: black;"> </span> </span></span></span></span><i><span style="font-size: x-small;"><span style="color: black;"> declare</span></span></i> </div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_cari</span><span style="color: black;"> </span><span style="color: black;">employees.first_name%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_depan</span><span style="color: black;"> </span><span style="color: black;">employees.first_name%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_belakang</span><span style="color: black;"> </span><span style="color: black;">employees.last_name%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">gaji</span><span style="color: black;"> </span><span style="color: black;">employees.salary%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">cursor </span><span style="color: black;">anu</span><span style="color: black;"> is </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">select </span><span style="color: black;">first_name</span><span style="color: black;">, </span><span style="color: black;">last_name</span><span style="color: black;">, salary</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">from employees</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">where </span><span style="color: black;">first_name</span><span style="color: black;"> = </span><span style="color: black;">nama_cari</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">begin</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_cari</span><span style="color: black;"> := '&</span><span style="color: black;">masukkan_nama</span><span style="color: black;">';</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">open </span><span style="color: black;">anu</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">loop</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span>fetch </span><span style="color: black;">anu</span><span style="color: black;"> into </span><span style="color: black;">nama_depan</span><span style="color: black;">, </span><span style="color: black;">nama_belakang</span><span style="color: black;">, </span><span style="color: black;">gaji</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span>exit when </span><span style="color: black;">anu%notfound</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span></span><span style="color: black;">dbms_output.put_line</span><span style="color: black;">('</span><span style="color: black;">pegawai</span><span style="color: black;"> </span><span style="color: black;">bernama</span><span style="color: black;"> '||</span><span style="color: black;">nama_depan</span><span style="color: black;">||' ' ||</span><span style="color: black;">nama_belakang</span><span style="color: black;">||' </span><span style="color: black;">gajinya</span><span style="color: black;"> </span><span style="color: black;">adalah</span><span style="color: black;"> USD '||</span><span style="color: black;">gaji</span><span style="color: black;">);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">end loop;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">close </span><span style="color: black;">anu</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">end;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 3.36pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">/</span></span></i><span style="font-size: x-small;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="font-family: "Courier New",Courier,monospace;"></span></span></span></span></div><br />
<div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="color: blue; font-size: x-small;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black; font-family: "Courier New",Courier,monospace;"> contoh 2: </span> </span></span></span></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="color: blue; font-size: x-small;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"> </span></span></span><i><span style="font-size: x-small;"><span style="color: black;"> declare</span></span></i> </div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_cari</span><span style="color: black;"> </span><span style="color: black;">employees.first_name%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_depan</span><span style="color: black;"> </span><span style="color: black;">employees.first_name%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">alamat_email</span><span style="color: black;"> </span><span style="color: black;">employees.email%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">telepon</span><span style="color: black;"> </span><span style="color: black;">employees.phone_number%type</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">cursor </span><span style="color: black;">anu</span><span style="color: black;"> is </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">select </span><span style="color: black;">first_name</span><span style="color: black;">, email, </span><span style="color: black;">phone_number</span><span style="color: black;"> </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">from employees</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">where </span><span style="color: black;">first_name</span><span style="color: black;"> = </span><span style="color: black;">nama_cari</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">begin</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">nama_cari</span><span style="color: black;"> := '&</span><span style="color: black;">masukkan_nama</span><span style="color: black;">';</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">open </span><span style="color: black;">anu</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">loop</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span>fetch </span><span style="color: black;">anu</span><span style="color: black;"> into </span><span style="color: black;">nama_depan</span><span style="color: black;">, </span><span style="color: black;">alamat_email</span><span style="color: black;">, </span><span style="color: black;">telepon</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span>exit when </span><span style="color: black;">anu%notfound</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span></span><span style="color: black;">dbms_output.put_line</span><span style="color: black;">('</span><span style="color: black;">Nama</span><span style="color: black;">: '||</span><span style="color: black;">nama_depan</span><span style="color: black;">); </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span></span><span style="color: black;">dbms_output.put_line</span><span style="color: black;">('Email: '||</span><span style="color: black;">alamat_email</span><span style="color: black;">||'@</span><span style="color: black;">SemogaJaya.co.id</span><span style="color: black;">');</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span></span><span style="color: black;">dbms_output.put_line</span><span style="color: black;">('</span><span style="color: black;">Telepon</span><span style="color: black;">: '||</span><span style="color: black;">telepon</span><span style="color: black;">);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;"><span> </span></span><span style="color: black;">dbms_output.put_line</span><span style="color: black;">(‘-----------------------------------------------------------’);</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">end loop;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">close </span><span style="color: black;">anu</span><span style="color: black;">;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">end;</span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 2.88pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black;">/</span></span></i></div><br />
<div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="color: blue; font-family: "Courier New",Courier,monospace; font-size: x-small;"><span style="font-size: small;"> </span></span></i><i><span style="font-size: x-small;"><span style="color: black;"> </span></span></i></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black;"><span style="color: red;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;">Menambahkan Exception Handling </span></span></span></span></span></div><div style="direction: ltr; font-family: "Courier New",Courier,monospace; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 4.08pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black;"><span style="color: red;"><span style="font-size: small;"><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"> setiap kesalahan (error) atau peringatan (warning) yang muncul karena suatu perintah disebut sebagai exception. blok exception dapat ditempatkan dalam blok sebagai exception handling</span> </span></span></span></span></span></div><span style="font-size: x-small;"><span style="color: black;"> </span></span><i><span style="font-size: x-small;"><span style="color: black;"> </span></span></i><br />
<br />
<div style="color: blue; font-family: "Courier New",Courier,monospace;">contoh peletakan exception:</div><div style="color: blue; font-family: "Courier New",Courier,monospace;"> <i><span style="font-size: x-small;"><span style="color: black;"> declare</span><br style="color: black;" /><span style="color: black;"> a employees.first_name%type;</span><br style="color: black;" /><span style="color: black;"> b employees.first_name%type;</span><br style="color: black;" /><span style="color: black;"> c employees.first_name%type;</span><span style="color: black;"> </span></span></i></div><div style="color: blue; font-family: "Courier New",Courier,monospace;"><i><span style="font-size: x-small;"><span style="color: black;"> begin</span><br style="color: black;" /><span style="color: black;"> c:='&nama_cari';</span><br style="color: black;" /><span style="color: black;"> select first_name, salary</span><br style="color: black;" /><span style="color: black;"> into a, b</span><br style="color: black;" /><span style="color: black;"> from employees</span><br style="color: black;" /><span style="color: black;"> where first_name = c;</span><br style="color: black;" /><span style="color: black;"> dbms_output.put_line('Gajinya '||a||' adalah USD '||B);</span><br style="color: black;" /><span style="color: black;"> <span style="color: red;"> <b>exception</b></span></span><b><br style="color: red;" /><span style="color: red;"> when no_data_found then</span><br style="color: red;" /><span style="color: red;"> dbms_output.put_line('Maaf nama '||c||' tidak ditemukan');</span><br style="color: red;" /><span style="color: red;"> when too_many_rows then</span><br style="color: red;" /><span style="color: red;"> dbms_output.put_line('Maaf nama '||c||' lebih dari 1 </span><br style="color: red;" /><span style="color: red;"> orang');</span></b><br style="color: black;" /><span style="color: black;"> end; </span><br style="color: black;" /><span style="color: black;"> /</span></span></i><br />
</div><br />
<span style="font-family: "Courier New",Courier,monospace;"><br />
</span>about my life ^_^http://www.blogger.com/profile/03212278237422880307noreply@blogger.com1tag:blogger.com,1999:blog-2737976624719060445.post-71174479294671201862010-11-16T08:06:00.000-08:002010-11-16T08:06:55.617-08:00Belajar Menulis dan Membaca Part 3 [Looping]<span style="font-size: x-small;">- LOOP</span><br />
<span style="font-size: x-small;"> strukutur simpel loop digunakan bila diinginkan minimal iterasi dijalankan satu kali. dalam struktur ini harus ditambahkan statement exit when untuk menghindari eksekusi tak terbatas (infinitif).</span><br />
<span style="font-size: x-small;"><br />
</span><br />
<div style="color: blue;"><span style="font-size: x-small;">contoh program yang memakai loop:</span></div><span style="font-size: x-small;"> </span><span style="font-size: x-small;"> <i>DECLARE</i></span><br />
<i><span style="font-size: x-small;"> total number(9);</span></i><br />
<i><span style="font-size: x-small;"> counter number(6);</span></i><br />
<br />
<i><span style="font-size: x-small;"> BEGIN</span></i><br />
<i><span style="font-size: x-small;"> total:=0;</span></i><br />
<i><span style="font-size: x-small;"> counter:=10;</span></i><br />
<i><span style="font-size: x-small;"> LOOP</span></i><br />
<i><span style="font-size: x-small;"> total:=total+counter;</span></i><br />
<i><span style="font-size: x-small;"> EXIT WHEN total > 50;</span></i><br />
<i><span style="font-size: x-small;"> END LOOP;</span></i><br />
<i><span style="font-size: x-small;"> DBMS_OUTPUT.PUT_LINE('Counter: ' || counter);</span></i><br />
<i><span style="font-size: x-small;"> DBMS_OUTPUT.PUT_LINE('Total: ' || total);</span></i><br />
<br />
<i><span style="font-size: x-small;"> END;</span></i><br />
<span style="font-size: x-small;"><i> /</i></span><br />
<br />
<span style="font-size: x-small;"><i>- </i>FOR</span><br />
<span style="font-size: x-small;"><i> </i>Struktur ini tidak memiliki kondisi, sehingga perlu didefinisikan indeks minimal dan maksimal sebagai batas iterasi. umumnya struktur ini digunakan untuk iterasi yang banyaknya sudah diketahui dengan pasti.</span><br />
<span style="font-size: x-small;"><br />
</span><br />
<div style="color: blue;"><span style="font-size: x-small;">contoh program yang memakai for:</span></div><div style="color: blue;"><span style="font-size: x-small;"> <u><span style="color: black;">contoh 1:</span></u> </span></div><span style="font-size: x-small;"> <i>DECLARE</i></span><br />
<i><span style="font-size: x-small;"> x number(3);</span></i><br />
<i><span style="font-size: x-small;"><br />
</span></i><br />
<i><span style="font-size: x-small;"> BEGIN</span></i><br />
<i><span style="font-size: x-small;"> x:=berapa;</span></i><br />
<i><span style="font-size: x-small;"> for i IN 1..x LOOP</span></i><br />
<i><span style="font-size: x-small;"> DBMS_OUTPUT.PUT_LINE('Ini angka ' || i);</span></i><br />
<i><span style="font-size: x-small;"> END LOOP;</span></i><br />
<i><span style="font-size: x-small;"> END;</span></i><br />
<span style="font-size: x-small;"><i> /</i></span><br />
<span class="toggle closed-toggle"><a href="javascript:void(0)"><br />
</a></span><br />
<span class="toggle closed-toggle"><a href="javascript:void(0)"> <span style="color: black;">contoh 2 (memakai IF)</span></a></span><br />
<br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> <i> Declare </i></span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> x number(3);</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> BEGIN</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> X:=&</span><span style="color: black; font-family: Arial;">berapa</span><span style="color: black; font-family: Arial;">;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> FOR </span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> IN 1..x LOOP</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span>if mod(i,2) = 1 then</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span>DBMS_OUTPUT.PUT_LINE('</span><span style="color: black; font-family: Arial;">Ini</span><span style="color: black; font-family: Arial;"> </span><span style="color: black; font-family: Arial;">angka</span><span style="color: black; font-family: Arial;"> ' || </span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> );</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span>else</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span>DBMS_OUTPUT.PUT_LINE('</span><span style="color: black; font-family: Arial;">Ini</span><span style="color: black; font-family: Arial;"> </span><span style="color: black; font-family: Arial;">angka</span><span style="color: black; font-family: Arial;"> ' || ‘</span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;">’ );</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span>end if;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> END LOOP;<br />
</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> END;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> /</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">- </span></span></i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">Statemen WHILE</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> Struktur ini selalu memeriksa kebenaran kondisi di awal blok iterasi. Bila kondisi bernilai FALSE, maka stateme<i>n-</i></span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">statemen dalam blok iterasi tidak akan dieksekusi.</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="color: blue; direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="font-family: Arial;">contoh program yang memakai WHILE:</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"> </div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">DECLARE</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> NUMBER(3);</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">hasil</span><span style="color: black; font-family: Arial;"> NUMBER(5);</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"> </span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">BEGIN</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;">:=1;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">WHILE </span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> <= 10 LOOP</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span></span><span style="color: black; font-family: Arial;">hasil</span><span style="color: black; font-family: Arial;"> := </span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;">**3;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span>DBMS_OUTPUT.PUT_LINE(</span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> ||' </span><span style="color: black; font-family: Arial;">pangkat</span><span style="color: black; font-family: Arial;"> 3 = '|| </span><span style="color: black; font-family: Arial;">hasil</span><span style="color: black; font-family: Arial;"> );</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><span> </span></span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> := </span><span style="color: black; font-family: Arial;">i</span><span style="color: black; font-family: Arial;"> + 1;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">END LOOP;</span></span></i></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><br />
</div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">END;</span></span></i></div><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;">/</span></span></i><br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.46in; margin-top: 5.04pt; text-align: left; text-indent: -0.42in; unicode-bidi: embed;"><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"><i> </i></span></span><i><span style="font-size: x-small;"><span style="color: black; font-family: Arial;"></span></span></i></div><span class="toggle closed-toggle"><span style="color: black;"></span></span><br />
<span style="font-size: x-small;"><i> </i></span>about my life ^_^http://www.blogger.com/profile/03212278237422880307noreply@blogger.com0tag:blogger.com,1999:blog-2737976624719060445.post-4358245652895447612010-10-13T10:09:00.000-07:002010-10-13T10:09:46.653-07:00Belajar Menulis dan Membaca Part 2 [IF Conditional]Perintah IF terdiri atas 3 bentuk, yaitu IF THEN, IF THEN ELSE, serta IF THEN ELSEIF. struktur dari ketiganya ditampilkan dalam satu rumusan umum sebagai berikut:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> </b></i><u><i><b>IF </b></i></u><i><b>kondisi 1 <u>THEN</u></b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> baris perintah....</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> [<u>ELSEIF</u> kondisi 2 <u>THEN</u></b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> baris perintah....]</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> ....</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> [<u>ELSE</u></b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> baris perintah...]</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> <u>END IF;</u></b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b><br />
</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">- IF THEN</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">pada struktur IF THEN, PL/SQL hanya mengecek sebuah kondisi. apabila kon</span><span style="font-family: Times,"Times New Roman",serif;">disi tersebut terpenuhi, maka statment-statment dalam blok pemilihan tersebut akan dieksekusikan terlebih dahulu sebelum dilanjutkan ke statment dibawah blok pemilihan.</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">- IF THEN ELSE</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">pada struktur ini, perlu di definisikan kondisi khusus untuk mengatasi apabila kondisi yang di definisikan pada blok IF tidak terpenuhi. kondisi khusus tersebut diletakkan pada bagian ELSE. apabila kondisi IF (bernilai TRUE) maka statement-statement A akan dieksekusi terlebih dahulu sebelum dilanjutkan ke statment yang berada di bawah blok pemilihan. bila kondisi IF tidak terpenuhi maka statment-statmen B yang akan di eksekusi terlebih dahulu sebelum dilanjutkan ke statment-statment yang berada di bawah blok pemilihan.</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">- IF THEN ELSEIF</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">pada struktur ini, minimal terdapat dua kondisi yang harus diperiksa dan satu tambahan kondisi khusus yang akan mengatasi kejadian dimana semua kondisi yang didefinisikan tidak terpenuhi (bernilai FALSE)</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="color: blue;">Contoh-contoh about IF</span></span></span><br />
<br />
<div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">contoh 1:</span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><b><span style="font-family: "Courier New",Courier,monospace;"> declare</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> x varchar(10);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> y number(5);</span></b></i></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><b><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> begin</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> x:= ‘tes';</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> Y:= 15;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('Selamat Datang '||x);</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> if y < 25 then</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line(‘tes lagi ah’);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> end if;</span></b></i></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><b><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> end;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> /</span></b></i></span></span></div><div style="color: black;"><br />
</div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">Contoh 2:</span></span></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i style="font-family: "Courier New",Courier,monospace;"><b> declare<br />
nama varchar(10);<br />
harga number(5);<br />
diskon number(3);<br />
bayar number(5);</b></i></span></span></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i style="font-family: "Courier New",Courier,monospace;"><b><br />
begin<br />
nama:= '&nama';<br />
harga:= &harga_buku;<br />
diskon := &diskon;<br />
dbms_output.put_line('Selamat Datang '||nama);<br />
bayar:= harga*((100-diskon)/100);<br />
dbms_output.put_line('Harga yang harus dibayar adalah rp.'||bayar);<br />
if diskon < 25 then<br />
dbms_output.put_line('pelit');<br />
end if;</b></i></span></span></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i style="font-family: "Courier New",Courier,monospace;"><b><br />
end;<br />
/</b></i> </span></span></span></span></div><div style="color: black;"><br />
</div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">Contoh 3:</span></span></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><b><span style="font-family: "Courier New",Courier,monospace;"> declare</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> jk varchar(10);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> umur number(5);</span></b></i></span></span></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><b><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> begin</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> jk := '&jenis_kelamin';</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> umur := &umur;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> if (umur > 60) then</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('inget mati...');</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> elsif (jk = 'L' and umur >= 25) or (jk='P' and umur >= 20) then</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('buruan nikah bisi expired');</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> elsif (jk = 'L' and umur < 25) or (jk='P' and umur < 20) then</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('belajar dulu yg bener');</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> end if;</span></b></i></span></span></span></span></div><div style="color: black;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><b><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> end;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> /</span></b></i><br />
<br />
<span style="font-size: large;"><b><span style="color: purple; font-family: Arial,Helvetica,sans-serif;">** Pengen tambah pinter ga DBMS nya??? Ayoo, buka CMD nya and let's go to Work an this example.. :))</span></b></span></span></span><span style="font-size: large;"><b><i style="color: purple; font-family: Arial,Helvetica,sans-serif;"> </i><br style="color: purple; font-family: Arial,Helvetica,sans-serif;" /><span style="color: purple; font-family: Arial,Helvetica,sans-serif;"> </span></b></span></span></span></div><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><span style="color: blue;"> </span> </span></span>about my life ^_^http://www.blogger.com/profile/03212278237422880307noreply@blogger.com0tag:blogger.com,1999:blog-2737976624719060445.post-21002953446842836332010-10-13T09:34:00.000-07:002010-10-13T09:34:16.768-07:00ANONYMOUS PL/SQL<div style="font-family: Arial,Helvetica,sans-serif;"><b>urutan penulisan koding anonymous PL:</b> </div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">declare</div><div style="font-family: Arial,Helvetica,sans-serif;">.................</div><div style="font-family: Arial,Helvetica,sans-serif;">.................</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">begin</div><div style="font-family: Arial,Helvetica,sans-serif;">.................</div><div style="font-family: Arial,Helvetica,sans-serif;">.................</div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;">end;</div><div style="font-family: Arial,Helvetica,sans-serif;">/</div><br />
1. Declaration Section<br />
Digunakan untuk mendefinisikan variabel, konstanta, dan seluruh exception yang di definisikan oleh user yang akan digunakan pada bagian eksekusi. penulisan blok ini dimulai dengan menulis DECLARE.<br />
contoh: <br />
<span style="font-family: "Courier New",Courier,monospace;"><i>declare</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i> v_nama mahasiswa.nama%type;</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i> v_nim mahasiswa.nim%type;</i></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">2. Executable section</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"> Digunakan untuk mengeksekusi/menjalankan blok perintah PL/SQL seperti pengulangan, percabangan, berisi statment SQL untuk memanipulasi data pada basis data dan statement PL/SQL untuk memanipulasi data dalam blok.</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">contoh:</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"> </span></span> <span style="font-family: "Courier New",Courier,monospace;"><i>declare</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i> v_nama mahasiswa.nama%type;</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i> v_nim mahasiswa.nim%type;</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><br />
begin</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i> <b>select nim,nama into v_nim, v_nama</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> from pegawai</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> where nim=30109229</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> dbms_output.put_line(v_nama);</b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b></b></i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> </b></i>end;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><i><b> </b>\</i></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"><i><span style="font-family: "Courier New",Courier,monospace;"> </span></i> </span><i> </i></span><br />
<br />
- Contoh 1: menampilkan tanggal, bulan, dan tahun<br />
<b><span style="font-size: small;"><i><span style="font-family: "Courier New",Courier,monospace;">declare</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> begin</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('now is '||to_char(SYSDATE,'DAY'));</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('date '||to_char(SYSDATE,'DD'));</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('month '||to_char(SYSDATE,'MONTH'));</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> dbms_output.put_line('year '||to_char(SYSDATE,'YYYY'));</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> end;</span></i></span></b><br />
<b><span style="font-size: small;"><i><span style="font-family: "Courier New",Courier,monospace;"> /</span></i></span></b><br />
<br />
<b>- </b>Contoh 2: menginputkan angka untuk mengetahui luas dan keliling suatu persegi <br />
<br />
<b><span style="font-size: small;"><i><span style="font-family: "Courier New",Courier,monospace;"> declare<br />
x number(3);<br />
y number(3);<br />
keliling number(3);<br />
luas number(3);<br />
<br />
begin<br />
x:=&nilai_x ;<br />
y:=&nilai_y ;<br />
keliling:= 2*(x+y);<br />
luas:= x*y;<br />
<br />
dbms_output.put_line('persegi panjanga ini kelilingnya '|| keliling|| 'cm'); <br />
dbms_output.put_line('Luasnya adalah '|| luas || 'cm');<br />
<br />
end;<br />
/</span></i></span></b><br />
<br />
<span style="font-size: small;"><i><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">- </span></span></i><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;">Contoh 3:Membuat Kalkulator </span></span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times,"Times New Roman",serif;"> <b><i style="font-family: "Courier New",Courier,monospace;"> declare<br />
x number(3);<br />
y number(3);<br />
z number(3);<br />
a number(3);<br />
b number(3);<br />
<br />
begin<br />
dbms_output.put_line('selamat datang di kalkulator cupu');<br />
x:=&nilai_x;<br />
y:=&nilai_y;<br />
z:=x+y;<br />
a:=x-y;<br />
b:=x*y;<br />
dbms_output.put_line(x||'ditambah'||y||'samadengan'||z);<br />
dbms_output.put_line(x||'dikurang'||y||'samadengan'||a);<br />
dbms_output.put_line(x||'dikali'||y||'samadengan'||b);<br />
<br />
end;<br />
/ </i></b></span></span></span><b><span style="font-family: "Courier New",Courier,monospace; font-size: small;"><i> </i></span></b><b><span style="font-size: small;"><i><span style="font-family: "Courier New",Courier,monospace;"></span></i></span></b><br />
<div style="color: red; font-family: Verdana,sans-serif;"><span style="font-size: small;"><i><br />
</i></span></div><div style="color: red; font-family: Verdana,sans-serif;"><span style="font-size: small;"><i>** </i></span><span style="font-size: small;">Pengen tau Outputan dari contoh2 di atas???</span></div><span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: red; font-family: Verdana,sans-serif;">biar DBMS nya pintar, ayooo coba sendiri okeh!!! :) </span></span></span>about my life ^_^http://www.blogger.com/profile/03212278237422880307noreply@blogger.com0tag:blogger.com,1999:blog-2737976624719060445.post-1447435855381186882010-10-13T08:57:00.000-07:002010-10-13T08:57:44.856-07:00DDL & DML<meta content="text/html; charset=utf-8" http-equiv="Content-Type"></meta><meta content="Word.Document" name="ProgId"></meta><meta content="Microsoft Word 12" name="Generator"></meta><meta content="Microsoft Word 12" name="Originator"></meta><link href="file:///C:%5CUsers%5CMega%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" rel="File-List"></link><link href="file:///C:%5CUsers%5CMega%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" rel="themeData"></link><link href="file:///C:%5CUsers%5CMega%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml" rel="colorSchemeMapping"></link> <m:smallfrac m:val="off"> <m:dispdef> <m:lmargin m:val="0"> <m:rmargin m:val="0"> <m:defjc m:val="centerGroup"> <m:wrapindent m:val="1440"> <m:intlim m:val="subSup"> <m:narylim m:val="undOvr"> </m:narylim></m:intlim> </m:wrapindent><style>
<!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;
mso-font-charset:2;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:0 268435456 0 0 -2147483648 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:1;
mso-generic-font-family:roman;
mso-font-format:other;
mso-font-pitch:variable;
mso-font-signature:0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:.5in;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:.5in;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
.MsoPapDefault
{mso-style-type:export-only;
margin-bottom:10.0pt;
line-height:115%;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:56755732;
mso-list-type:hybrid;
mso-list-template-ids:-555692632 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l1
{mso-list-id:1122336000;
mso-list-type:hybrid;
mso-list-template-ids:683171622 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l2
{mso-list-id:1801027525;
mso-list-type:hybrid;
mso-list-template-ids:1008645822 -1318321396 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:-;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style> </m:defjc></m:rmargin></m:lmargin></m:dispdef></m:smallfrac><br />
<div class="MsoNormal" style="text-align: justify;"><b><span style="line-height: 115%;">INSERT<o:p></o:p></span></b></div><div class="MsoListParagraph" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Format MENAMBAH DATA JIKA SEMUA KOLOM AKAN DIISI:<o:p></o:p></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>INSERT INTO Nama_Tabel VALUES (<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>Data_kolom1,<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>Data_kolom2,<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>Data_kolom3<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>);<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraph" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh penggunaan Insert jika semua kolom ingin diisi:<o:p></o:p></b></div><div class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"><span style="font-family: "Courier New"; line-height: 115%;">insert into anggota values( <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in; text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">30109229, <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"><span style="font-family: "Courier New"; line-height: 115%;">‘Megawati Dini A, <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify; text-indent: 0.5in;"><span style="font-family: "Courier New"; line-height: 115%;">‘Tasikmalaya’<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><span style="font-family: "Courier New";">);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><br />
</div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>FORMAT MENAMBAH DATA JIKA HANYA KOLOM TERTENTU YANG DIISI:<o:p></o:p></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><i>INSERT INTO Nama_Tabel (Nama_Kolom1, Nama_Kolom2)<o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><i>VALUES (<o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><i>Data_kolom1,<o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><i>Data_kolom2<o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><i>);<o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh Menambah data pada tabel anggota hanya pada kolom-kolom tertentu saja:<o:p></o:p></b></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">insert into registrasi (id_anggota, jenis_kelamin, tanggal_lahir) <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">values( <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">‘BA6369’, <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">Perempuan, <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">’14-MAY-1991’<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-family: "Courier New";">);</span><o:p></o:p></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><b><span style="font-size: 12pt;">** Note:<o:p></o:p></span></b></div><div class="MsoListParagraphCxSpMiddle" style="margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">-<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Insert untuk semua kolom memperhatikan urutan kolom sesuai perintah DESC Nama_Tabel</div><div class="MsoListParagraphCxSpMiddle" style="margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">-<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Untuk tipe data selain number penulisan data diapit dengan petik tunggal (‘)</div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify; text-indent: -0.25in;">-<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Format Penulisan Date : DD-MON-YYYY (2 digit tanggal, 3 digit awal bulan dalam bhs inggris, 4 digit tahun)</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><b><span style="font-size: 12pt;"><o:p> </o:p></span>UPDATE<o:p></o:p></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpLast" style="margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>FORMAT MENGUBAH DATA<o:p></o:p></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>UPDATE Nama_Tabel <o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>SET Nama_Kolom = data_baru<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; text-align: justify; text-indent: 0.5in;"><i>WHERE syarat_perubahan_data;<o:p></o:p></i></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh 1:Mengubah semua alamat anggota menjadi ‘Tasikmalaya ’<o:p></o:p></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><span style="font-family: "Courier New";">update anggota set alamat_anggota = ‘Tasikmalaya’;<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh 2: Mengubah no_anggota dari 100 menjadi 105</b></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">update anggota set no_anggota = 105<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><span style="font-family: "Courier New";">where no_anggota = 100;<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh 3:</b> Mengubah semua alamat anggota menjadi Tasikmalaya’ jika nomor anggota antara 200 dan 300</div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">update anggota set alamat_anggota = ‘Tasikmalaya’<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><span style="font-family: "Courier New";">where (no_anggota >= 200) and (no_anggota <= 300);<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><b>DELETE<o:p></o:p></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>FORMAT MENGHAPUS DATA: <o:p></o:p></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><i>DELETE FROM Nama_Tabel <o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><i>WHERE syarat_perubahan_data ;<o:p></o:p></i></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh1: Menghapus seluruh isi tabel anggota</b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-family: "Courier New";">delete from anggota ;</span><span style="font-size: 13pt;"><o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh2: Meghapus data anggota yang nomor anggotanya 100</b></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">Delete from anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-family: "Courier New";">where no_anggota = 100;<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh3: Menghapus semua data anggota yang nomor anggotanya mulai 200 sampai 300</b></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">delete from anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><span style="font-family: "Courier New";">where (no_anggota >= 200) and (no_anggota <= 300);</span><span style="font-size: 13pt;"><o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoNormal" style="text-align: justify;"><b><span style="line-height: 115%;"> SELECT … FROM … WHERE<o:p></o:p></span></b></div><div class="MsoListParagraph" style="margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Format Query Data: <o:p></o:p></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>SELECT daftar_kolom<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;"><i>FROM daftar_tabel<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; text-align: justify; text-indent: 0.5in;"><i>WHERE syarat_dan_atau_foreign_key<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; text-align: justify; text-indent: 0.5in;"><br />
</div><div class="MsoListParagraph" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Fungsi Agregat: </b><i>MIN(), MAX(), AVG(), SUM(), COUNT()<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 1.5in; text-align: justify; text-indent: -1in;"><i>SELECT daftar_kolom_non_fungsi_ag, fungsi_ag(nama_kolom1), fungsi_ag(nama_kolom2)<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>FROM daftar_tabel<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>WHERE syarat_dan_atau_foreign_key<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><i>GROUP BY daftar_kolom_non_fungsi_ag<o:p></o:p></i></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">(*) Fungsi agregat dapat digunakan sebagai pengganti daftar kolom, digunakan setelah SELECT... </div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">(*) Jika setelah SELECT digunakan fungsi agregat bersama kolom yang lain yang bukan fungsi agregat maka HARUS menggunakan klausa GROUP BY. Perhatikan contoh 3,4,5 dan 6</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh1:</b> Menampilkan nama dan alamat anggota yang diawali huruf A dan terdiri dari 5 huruf</div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New";">select nama_anggota, alamat_anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New";">from anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-family: "Courier New";">where nama_anggota like 'A____';<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh2:</b> Menampilkan nama anggota dan judul buku yang diawail huruf W dan terdiri dari MINIMAL 8 huruf:</div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">select nama_anggota, judul_buku<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">from anggota, buku, peminjaman<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">where anggota.no_anggota = peminjaman.no_anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">and buku.id_buku = peminjaman.id_buku<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-family: "Courier New";">and judul_buku like 'W_______%';<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b>Contoh3:</b> Menampilkan jumlah buku yang pernah dipinjam oleh Ngatiyem (dengan menampilkan nama Ngatiyem)</div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">select nama_anggota, count(id_buku) as jmlbuku<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">from peminjaman, anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">where anggota.no_anggota = peminjaman.no_anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">and nama_anggota = 'Ngatiyem'<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-family: "Courier New";">group by nama_anggota;</span><span style="font-size: 13pt;"><o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol; font-size: 13pt;">·<span style="font-family: "Times New Roman"; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span><b><span style="font-size: 13pt;">Contoh 4:</span></b><span style="font-size: 13pt;"> Menampilkan judul buku dan tanggal peminjaman buku oleh Ngatimin yg tidak dikembalikan<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">select judul_buku, tanggal_pinjam<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">from peminjaman, anggota, buku<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">where anggota.no_anggota = peminjaman.no_anggota<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">and buku.id_buku = peminjaman.id_buku<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle"><span style="font-family: "Courier New"; line-height: 115%;">and nama_anggota = 'Ngatimin'<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="text-align: justify;"><span style="font-family: "Courier New"; line-height: 115%;">and tanggal_kembali is null;</span><b><span style="font-size: 13pt; line-height: 115%;"><o:p></o:p></span></b></div>about my life ^_^http://www.blogger.com/profile/03212278237422880307noreply@blogger.com0