Selasa, 09 November 2010

kisi2 dbms

declare
a number :=&va;
b number :=&vb;
c number;
begin
c:=a/b;
dbms_output.put_line (c);
exception
when zero_divide then
dbms_output.put_line ('pembagi tidak boleh :=0');
when value_error then
dbms_output.put_line('terjadi kesalahan variabel');
end;
/



declare
a number :=&va;
b number :=&vb;
c number;
dibagi_nol exception;
begin
if b=0 then
raise dibagi_nol;
else
c:=a/b;
dbms_output.put_line (c);
end if;
exception
when dibagi_nol then
dbms_output.put_line ('pembagi tidak boleh :=0');
end;
/




declare
a number :=&va;
b number :=&vb;
c number;
begin
c:=a/b;
dbms_output.put_line (c);
exception
when zero_divide then
raise_application_error(9,'pembagian dengan 0',true);
when value_error then
dbms_output.put_line('terjadi kesalahan variabel');
end;
/


1.)
declare
a number:=&va;
nilai exception;
begin
if a>=1 then
raise nilai;
else
dbms_output.put_line('itu bukan bilangan positif');
end if;
exception
when nilai then
dbms_output.put_line('itu bilangan positif');
end;
/

2.)
declare
a number:=&va;
nim exception;
begin
if length (a)>=9 then
raise nim;
else
dbms_output.put_line ('sudah benar');
end if;
exception
when nim then
dbms_output.put_line('maaf digit terlalu banyak');
end;
/


3.)

create table error_log
(
error_time varchar2 (100),
error_description varchar2 (100)
);

insert into error_log
values ('sysdate','fmDD Month YYYY', 'HH24:MI:SS AM')
;

declare
id varchar2(100):='&v_employee_id';
cursor cursor_employees is select first_name, last_name, department_name
from employees, departments
where employees.employee_id=departments.department_name and employees.employee_id=id;
cari exception
begin
if
for rec in cursor_employees loop
raise cari;
else
dbms_output.put_line('informasi pegawai='||rec.first_name||rec.last_name);
dbms_output.put_line('nama department='||rec.department_name);
end if;
exception
when cari then
dbms_output.put_line('data eror');
end loop;
end;
/

Tidak ada komentar:

Posting Komentar