الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

عمل Trigger

Featured Replies

بتاريخ:

مثال في جدول EMP
أريد عمل trigger
عند القيام بأدخال رقم موظف في جدول emp موجود يقوم بحذف سجيل هذا الموظف وأدخال السجيل الجديد

بتاريخ:

السلام عليكم ورحمة الله وبركاته

اخي الكريم

الـ trigger التالي يقوم بحذف السجل السابق قبل عملية ادخال السجل الجديد الذي يحتوي علي نفس الرقم الوظيفي

create  or  replace  trigger   t_emp   before  insert  on   emp   for  each  row
declare
id  number;
begin
select count(empno) into id  from  emp  where  empno = :new.empno;
if  id = 1 then
delete from  emp where empno = :new.empno;
end if ; 
end; 



حيث بهذه الطريقة سوف تفقد بيانات الموظف السابق الذي كان يحمل نفس الرقم الوظيفي

لذلك من الأفضل إنشاء جدول ثاني يتم فيه إدخال البيانات التي تم حذفها في الجدول الأول

إنشاء الجدول

copy from scott/1@orcl to scott/1@orcl create emp2 using SELECT * FROM  emp WHERE  empno = 0;



إدخال عمود جديد يحتوي علي تاريخ الحذف

ALTER  TABLE  emp2  ADD ( dat  date );




تعديل الـ trigger السابق كما يلي

create  or  replace  trigger   t_emp   before  insert  on   emp   for  each  row
declare
id  number;
begin
select count(empno) into id  from  emp  where  empno = :new.empno;
if  id = 1 then
insert  into  emp2 ( dat , EMPNO , ENAME , JOB , MGR , HIREDATE , SAL , COMM , DEPTNO ) 
select  sysdate , EMPNO , ENAME , JOB , MGR , HIREDATE , SAL , COMM , DEPTNO  from  emp   where empno = :new.empno;
delete from  emp where empno = :new.empno;
end if ; 
end; 



جزاك الله كل خير

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

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

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

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

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

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.