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

بتاريخ:

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

كيف لي انشاء حقل محسوب يتم فيه جمع القيم السابقه له ,,,,

مثلا لدي ثلاث حقول f1 و f2 و f3 حيث ان f3 هو الحقل المحسوب بهذا الشكل .

-----------------------------------------------
f1 | f2 | f3
-----------------------------------------------
1 | 100 | 100
2 | 200 | 300
3 | 600 | 900
-----------------------------------------------

مثلا في الصف الاول f3 = اجمالي f2 حتى هذا الصف = 100
و في الصف الثاني f3 = اجمالي f2 حتى هذا الصف = 100 + 200 = 300
و في الصف الثالث f3 = اجمالي f2 حتى هذا الصف = 100 + 200 + 600 = 900

وهكذاااااا ,,,,,,,,,,,,

ارجو ان اجد الحل لديكم

بالتوفيق

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

بتاريخ:

نفرض أن لدينا الجدول التالي :

Create Table Emp
(
  Emp_ID		Number(10),
  Emp_Name   VarChar2(20),
  Emp_Salary   Number(10,3),
  Constraint PK_EMP Primary Key(Emp_ID)
)
/
Insert Into Emp Values(1,'Ahmed',100);
Insert Into Emp Values(2,'Usif',200);
Insert Into Emp Values(3,'Sara',300);
Insert Into Emp Values(4,'Walead',400);
Insert Into Emp Values(5,'Mostapha',500);
Commit;



الطريقة الأولي : إستخدام جمل الإستعلام :

Select E1.Emp_ID,E1.Emp_Name,E1.Emp_Salary,
	   (Select Sum(E2.Emp_Salary) From Emp E2 Where E2.Emp_ID 
	  <= E1.Emp_ID) As Emp_Sum_Salary
From Emp  E1
Order By Emp_ID;



نفس الطريقة الأخري ولكن بالعكس :

Select E1.Emp_ID,E1.Emp_Name,E1.Emp_Salary,
	   (Select Sum(E2.Emp_Salary) From Emp E2 Where E2.Emp_ID 
	  >= E1.Emp_ID) As Emp_Sum_Salary
From Emp  E1
Order By Emp_ID;



الطريقة الثانية : إستخدام PL/SQL وتعقيداتة :

Create Or Replace Type O_Emp Is Object
(
 Emp_ID  Number(10),
 Emp_Name  VarChar2(20),
 Emp_Salary Number(10,3),
 Emp_Sum_Salary Number(10,3)
);
/

Create Or Replace Type T_Emp Is Table Of O_Emp;
/

Create Or Replace Function Get_Emp(Sum_Type  Number Default 0) Return T_Emp
As
Type T_Cur_Emp Is Ref Cursor;
Cur_Emp  T_Cur_Emp;
ID_Serial	Number;
ID_Name	VarChar2(20);
ID_Salary   Number(10,3);
ID_Sum	  Number(10,3);

p_Emp  T_Emp := T_Emp();
Begin
ID_Sum := 0;
If(Sum_Type = 0)Then
	Open Cur_Emp For Select Emp_ID,Emp_Name,Emp_Salary
									 From Emp
									 Order By Emp_ID;
Else
	Open Cur_Emp For Select Emp_ID,Emp_Name,Emp_Salary
									 From Emp
									 Order By Emp_ID Desc;
End If;
Fetch Cur_Emp Into ID_Serial,ID_Name,ID_Salary;
While Cur_Emp%Found
Loop
	ID_Sum := ID_Sum + ID_Salary;
	p_Emp.ExtEnd;
	p_Emp(p_Emp.Count) := O_Emp(ID_Serial,ID_Name,ID_Salary,ID_Sum);
	Fetch Cur_Emp Into ID_Serial,ID_Name,ID_Salary;
End Loop;
Close Cur_Emp;

Return p_Emp;
End;
/



ومن ثم إستدعائة كما يلي :

Select * From Table(Get_Emp);
-- أو --
Select * From Table(Get_Emp(0));
-- أو --
Select * From Table(Get_Emp(1));





بالتوفيق

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

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

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

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

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

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.