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

أريد شرح أمر Merge لو سمحتم

Featured Replies

بتاريخ:

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


ممكن يا أخوتي في الله
أحد يشرح لي امر Merge
وأكون له من الشاكرين
وشكرا

بتاريخ:

Examples
Merging into a Table: Example The following example uses the bonuses table in the sample schema oe with a default bonus of 100. It then inserts into the bonuses table all employees who made sales, based on the sales_rep_id column of the oe.orders table. Finally, the human resources manager decides that employees with a salary of $8000 or less should receive a bonus. Those who have not made sales get a bonus of 1% of their salary. Those who already made sales get an increase in their bonus equal to 1% of their salary. The MERGE statement implements these changes in one step:

CREATE TABLE bonuses (employee_id NUMBER, bonus NUMBER DEFAULT 100);
INSERT INTO bonuses(employee_id)
  (SELECT e.employee_id FROM employees e, orders o
  WHERE e.employee_id = o.sales_rep_id
  GROUP BY e.employee_id);
SELECT * FROM bonuses; EMPLOYEE_ID      BONUS
----------- ----------
       153        100
       154        100
       155        100
       156        100
       158        100
       159        100
       160        100
       161        100
       163        100
MERGE INTO bonuses D
  USING (SELECT employee_id, salary, department_id FROM employees WHERE department_id = 80) S ON (D.employee_id = S.employee_id)
  WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
    DELETE WHERE (S.salary > 8000)
  WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
    VALUES (S.employee_id, S.salary*0.1)
    WHERE (S.salary <= 8000);
EMPLOYEE_ID      BONUS
----------- ----------
       153        180
       154        175
       155        170
       159        180
       160        175
       161        170
       179        620
       173        610
       165        680
       166        640
       164        720
       172        730
       167        620
       171        740


بكل بساطه merge تستخدم لعمل translate من جدول لاخر ولكنها قبل عمل النقل للبيانات تتاكد اذاكانت نفس البيانات متاوجده في الجدول الجديد عندها تقوم بعمل update لها واذا كانت هذه البيانات غير موجوده تعمل لها insert

بتاريخ:
  • كاتب الموضوع

بارك الله فيك


أخي
sasa87
وجزاك الجنة

بتاريخ:

شرح وتبسيط جميل من اخ فاضل

  • بعد 3 أسابيع...
بتاريخ:

ابسطك الله وجزاك كل خير

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

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

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

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

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

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.