PL/SQL Ders15 - Exception


   PL/SQL'de 2 tip exception (istisna) vardır. Bunlar
  • Sistem tabanlı exception
  • Kullanıcı tabanlı exception
DECLARE
....
BEGIN
....

EXCEPTION
    WHEN ..... THEN
    ..........
    WHEN ..... THEN
    ..........
END;



Worksheet15.sql
DECLARE
   p_id   test_personel.id%TYPE;
BEGIN
   SELECT id
     INTO p_id
     FROM test_personel
    WHERE ad = 'enes22';
    DBMS_OUTPUT.put_line (p_id);
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      DBMS_OUTPUT.put_line ('veri bulunamadi..');
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('bir hata var..');
END;



Raising Exceptions (Kullanıcı Tabanlı)

Istisnalar veri tabanında dahili bir hata meydana geldiğinde otomatik olarak oluşturulur. Fakat programcı tarafından RAISE komutuyla da explicit (açık) bir şekilde istisna tanımlanabilir.

Bir istisna tanımlamasını ve o istisnanın meydana gelmesi durumda yapılacakları gösteren genel kod bloğu aşğıdaki gibidir.


DECLARE 
   istisnaIsmi EXCEPTION; 
BEGIN 
   IF kosul THEN 
      RAISE istisnaIsmi; 
   END IF; 
EXCEPTION 
   WHEN istisnaIsmi THEN 
      ....
END; 

Worksheet15_2.sql
DECLARE
   kucukSayi   EXCEPTION;
   sayi        INT := 9;
BEGIN
   IF sayi < 10
   THEN
      RAISE kucukSayi;
   ELSE
      DBMS_OUTPUT.PUT_LINE ('sayi : ' || sayi);
   END IF;
   
EXCEPTION
   WHEN kucukSayi
   THEN
      DBMS_OUTPUT.PUT_LINE ('sayi 10dan kucuk olamaz..');
END;

PL/SQL Exception

Yorumlar

Bu blogdaki popüler yayınlar

Java SE Ders24 - Composition (Kompozisyon)

Spring Ders20 - Aspect Oriented Programming - AspectJ Annotation Style

JSF Ders30 - Page Template (Sayfa Şablonu)