Minggu, 18 April 2010

PL / SQL (bagian 2)

nie sambuangan materi PL/sql nyang aye pelajarin di lab.

4. Bilangan Ganjil

SET SERVEROUTPUT ON

DECLARE

I INTEGER;

K INTEGER;

BEGIN

K:=&input;

FOR I IN 1..k LOOP

DBMS_OUTPUT.PUT(TO_CHAR(I*2-1));

END LOOP;

DBMS_OUTPUT.new_line;

END;

5. Perulangan

Output Ke bawah

SET SERVEROUTPUT

DECLARE

I INTEGER;

BEGIN

FOR I IN 1..5 LOOP

DBMS_OUTPUT.PUT_LINE(TO_CHAR(I));

END LOOP;

END;

Output Ke Atas

SET SERVEROUTPUT ON

DECLARE

I INTEGER;

BEGIN

FOR I IN 1..5 LOOP

DBMS_OUTPUT.PUT(TO_CHAR(I));

END LOOP;

DBMS_OUTPUT.new_line;

END;

6. Bilangan Ganjil dan Genap

SET SERVEROUTPUT ON

DECLARE

I INTEGER ;

BEGIN

I := &INPUT_NILAI ;

IF (I MOD 2=0) THEN

DBMS_OUTPUT.PUT_LINE('GENAP');

ELSE

DBMS_OUTPUT.PUT_LINE('GANJIL');

END IF;

END;

7. Deret Segitiga

set serveroutput on;
declare
a integer;
b integer;
begin
a:=0;
loop
a:=a+1;
dbms_output.put_line('');
b:=1;
loop
dbms_output.put('*');
exit when b=a;
b:=b+1;
end loop;
exit when a=4;
end loop;
end;

8. mutu nilai

SET SERVEROUTPUT ON

DECLARE

UTS INTEGER:=2;

UAS INTEGER:=2;

MUTU VARCHAR2(6);

TOTAL NUMBER;

BEGIN

UTS:=&NILAI_UTS_ANDA;

UAS:=&NILAI_UAS_ANDA;

TOTAL := ((0.4*UTS) + (0.6*UAS)) ;

IF (TOTAL >=85) THEN

MUTU := 'A';

ELSE IF (TOTAL <= 84 AND TOTAL >= 75) THEN

MUTU := 'B';

ELSE IF (TOTAL <=74 AND TOTAL >=65) THEN

MUTU := 'C';

ELSE IF (TOTAL <=54 AND TOTAL >=45) THEN

MUTU := 'D';

ELSE

MUTU := 'E';

END IF;

END IF;

END IF;

END IF;

DBMS_OUTPUT.PUT_LINE('Nilai Anda ' || TO_CHAR(TOTAL) ||' '|| 'Maka Mutu Nilai Anda Adalah ' || INITCAP(MUTU));

END;

s'moga bermanfaat wat belajar dan latihan para pembaca, khusus nyang sedang mempelajari PL/SQL. s'moga bisa membantu...
terima kasih...

0 komentar:

Posting Komentar

bagus sekali

Pages

Recent Comments

Introduction

Recent Posts