الانتقال إلى المحتوى
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.

حذف السجلات المكررة في جدول

Featured Replies

بتاريخ:

حذف السجلات المكررة من جدول

declare
 كورسور يجمع السجلات المكررة من جدول
  
cursor target_cur is	select fcn	from   table1	group  by fcn	having count (fcn) > 1;
  
hold_fcn varchar2(4);

 كورسور يستقبل حقل من السجل المكرر و يرتب البيانات تنازليا للابقاء على اخر سجل تم اضافته و حذف سابقيه

cursor delete_cur (hold_fcn in varchar2) is   select fcn,  id  from   table1   where  fcn = hold_fcn 
order  by id desc 	 for update nowait;
   
  
delete_rec delete_cur%rowtype;
 
first_fetch_sw varchar2(1);
  
begin
open target_cur;

loop

	fetch target_cur into hold_fcn;
	exit  when target_cur%notfound or
						  target_cur%notfound is null;
   
	 
		open delete_cur (hold_fcn);
		first_fetch_sw := 'Y';
	  
		loop
			fetch delete_cur into delete_rec;
			exit  when delete_cur%notfound or
								  delete_cur%notfound is null;
		   
			if first_fetch_sw = 'Y' then
				first_fetch_sw := 'N';
			else
						
				delete from table1 where current of delete_cur;
			  
			end if;
		end loop;

		close delete_cur;
			  
end loop;
close target_cur;
 
commit;

end;

بتاريخ:
Create Table TBL
(
  TBL_ID Number(10),
  TBL_Name VarChar2(20),
  Constraint PK_TBL Primary Key(TBL_ID)
)
/

Insert Into TBL Values(1,'Ahmed');
Insert Into TBL Values(2,'Usif');
Insert Into TBL Values(3,'Sara');
Insert Into TBL Values(4,'Mohamed');
Insert Into TBL Values(5,'Ahmed');
Insert Into TBL Values(6,'Dina');
-- Ahmed من المفروض حذف السجل الذي يدعي --

Select * 
From TBL 
Where TBL_Name In(Select TBL_Name From TBL Group By TBL_Name Having Count(TBL_ID) > 1)

تم تعديل بواسطة MMA

بتاريخ:

والحذف طبعاً يبقى كده :

delete emp where ename in (select ename from emp where ename in (select ename from emp group by ename having count(empno)>1))



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

  • بعد 2 أسابيع...
بتاريخ:
  • كاتب الموضوع

لكن المشكلة الاخ احمد ان هذا الكود يحذف السجلات المكررة مع السجل الاصلي
اي اذا كان هناك اي سجل مكرر اكثر من مرة يحذفه نهائيا

ارجوا من لديه حل افضل ان يطرحه لتعم الفائدة

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

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

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

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

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

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.