الانتقال إلى المحتوى

سؤال في(الاستثناء)exception ارجو الاجابة بسرعه


koi

Recommended Posts

سؤال في (الاستناء) exception ا رجو الاجابة عليه بأسرع وقت ممكن

 

مطلوب برنامج لاستراجاع اسم الموظف صاحب راتب معين

1-اذا الراتب المدخل تسبب في استرجاع اكثر من سطر عالج الاستناء الناتج بالمعالج المناسب وادرج في جدول messages الرسالة "هناك اكثر من موظف لهم راتب (salary)

 

2-اذا الراتب المدخل لم يسترجع اي سطر عالج الاستثناء الناتج بالمعالج المناسب وادرج في جدول messages الرسالة "لايوجد موظفون لهم رواتب (salary)

 

3-اذا الراتب المدخل يسترجع سطرا واحد فقط ادرج في جدول messages الرسالة "اسم الموظف وراتبه

 

4-عالج اي استثناء اخر بالمعالج المناسب وادرج في جدول messages الرسالة "حدث هناك خطأ ما"

 

5-قم بتجريب الحالات المختلفة في البرنامج المكتوب وتفحص محتويات الجدول messages

 

RESULTS

محمد - 2000

هناك اكثر من موظف له راتب 500

لايوجد موظفون لهم رواتب 3500

تم تعديل بواسطة koi
رابط هذا التعليق
شارك

declare
v_sal emp.sal%type;
v_name emp.ename%type;
v_value messages.results%type;
begin select ename 
into v_name from emp where sal=800;

v_value := v_name||800;
insert into messages values(v_value);
commit;
exception 
when too_many_rows then
    begin v_value := 'there are more than one emp take this salary '||800;
     insert into messages values(v_value);
   commit;
   end; 
when no_data_found then
    begin v_value := 'No emp take this salary = '|| 800;
     insert into messages values(v_value);
   commit;
   end; 
when others then
    begin v_value := 'there are an error';
     insert into messages values(v_value);
commit;
   end; 


end;

SQL> select * from messages; RESULTS
----------------------------------------------------------------------------------------------------
there are more than one emp take this salary 3000
No emp take this salary = 500
SMITH800

3 rows selected.

SQL>


ارجو ان يكون اجتهادي صايبا ولا تنسانا من دعواتك
وان اردت باقي الاسئله اخبرني وشكرا لك

تم تعديل بواسطة تركي936
رابط هذا التعليق
شارك

السلام عليكم
أحببت أن أضع طلبك في
procedure
ولكن لاأظن أنه من الضروري أن نضع النتائج في
table



SQL> create or replace procedure empsal (p_sal in out number )
2 is
3 v_ename varchar2(20) ;
4 begin
5 select sal,ename
6 into p_sal,v_ename
7 from emp
8 where sal=p_sal ;
9 dbms_output.put_line(p_sal||'>>>>>>>>>'||v_ename);
10 insert into empsal1
11 values
12 (v_ename,p_sal,sysdate);
13 commit ;
14 exception when no_data_found then
15 insert into empsal1
16 values
17 ('no emp with this sal',p_sal,sysdate);
18 when too_many_rows then
19 insert into empsal1
20 values
21 ('there is more than emp with this sal',p_sal,sysdate);
22 when others then
23 dbms_output.put_line ('********other error********');
24 end;
25 /

Procedure created.

SQL> select * from empsal1;

no rows selected

SQL> var x number
SQL> begin
2 :x:=5000;
3 end;
4 /

PL/SQL procedure successfully completed.

SQL> exec empsal(:x);
5000>>>>>>>>>KING

PL/SQL procedure successfully completed.

SQL> select * from empsal1;

NAME
-----------------------------------------------------------------------------------
SAL TIME
---------- ---------
KING
5000 22-MAR-05


SQL> var x number
SQL> begin
2 :x:=525;
3 end;
4 /

PL/SQL procedure successfully completed.

SQL> exec empsal(:x);

PL/SQL procedure successfully completed.

SQL> select * from empsal1;

NAME
-----------------------------------------------------------------------------------
SAL TIME
---------- ---------
KING
5000 22-MAR-05

no emp with this sal
525 22-MAR-05


SQL> var x number
SQL> begin
2 :x:=3000;
3 end;
4 /

PL/SQL procedure successfully completed.

SQL> select * from empsal1;

NAME
-----------------------------------------------------------------------------------
SAL TIME
---------- ---------
KING
5000 22-MAR-05

no emp with this sal
525 22-MAR-05


SQL> exec empsal(:x);

PL/SQL procedure successfully completed.

SQL> select * from empsal1;

NAME
-----------------------------------------------------------------------------------
SAL TIME
---------- ---------
there is more than emp with this sal
3000 22-MAR-05

KING
5000 22-MAR-05

no emp with this sal
525 22-MAR-05

رابط هذا التعليق
شارك

  • بعد 2 أسابيع...

السلام عليكم ورحمة الله وبركاته،،
أتمني أن تفيدك إجابتي :
exception
when too_many_rows then
dbms_output.put_line ('there are many employees have this salary')
return 'there are many employees have this salary' ;
when no_data_found then
dbms_output.put_line ('there is no employee have this salary');
return 'there is no employee have this salary';
when others then
dbms_output.put_line ('unknown error')
return 'unknown error';

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية