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

بتاريخ:

السادة / اعضاء المنتدى الكرام..............
لدى قاعة بيانات صغيرة , وأود عمل trigger او sql statement تقوم بعمل حد اقصى للصفوف (Rows) داخل جدول معين.
برجاء التكرم بالافادة للاهمية,,,,,,,, و شكرا,,,,,,,

بتاريخ:

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

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

الهدف ان الجدول المطلوب تحديد الصفوف له هو جدول الصلاحيات للمستخدمين , ولا اريد ان يزيد عدد المستخدمين عن الحد المسموح به.

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


اخى ahmedbb , هل يمكن ان تضع مثالا ل PL/SQL كود يقوم بعد الصفوف وفى حالة تجاوزها العدد المسموح , يتم رفض ادخال سجل جديد.

بتاريخ:

السلام عليكم

CREATE OR REPLACE TRIGGER --TRIGGER name  
BEFORE  INSERT
ON --table name
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_count NUMBER;
BEGIN
IF INSERTING THEN
-----
--select  return count  row
IF /*count row */ >= 0 THEN
RAISE_APPLICATION_ERROR(-20099,'YOU MSG ');
END IF;
--  EXCEPTION
 --   WHEN OTHERS THEN
   -- Consider logging the error and then re-raise
---   RAISE;
END ;

بتاريخ:

السلام عليكم
CREATE OR REPLACE TRIGGER --TRIGGER name  
BEFORE  INSERT
ON --table name
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_count NUMBER;
BEGIN
IF INSERTING THEN
-----
--select  return count  row
IF /*count row */ >= 0 THEN
RAISE_APPLICATION_ERROR(-20099,'YOU MSG ');
END IF;
--  EXCEPTION
 --   WHEN OTHERS THEN
   -- Consider logging the error and then re-raise
---   RAISE;
END ;




You should add below code to declaration section to avoid mutual exception


pragma autonomous_transaction

بتاريخ:

The best solution to do this to create materialized view and create check constraint on materialize view



assume that your table as below

CREATE TABLE USERS_TABLE (USER_ID VARCHAR2 (50), USER_NAME VARCHAR2 (100));



then create below materialize view




CREATE MATERIALIZED VIEW LOG ON USERS_TABLE WITH ROWID(USER_ID) INCLUDING NEW VALUES;

CREATE MATERIALIZED VIEW mv
 REFRESH FAST
 ON COMMIT
AS
SELECT 1 dummy, COUNT(1)  no_of_rows
  FROM USERS_TABLE
 GROUP BY 1;




Now add check constraint to materialize view



ALTER TABLE MV ADD CONSTRAINT CHECK_MAX_USERS CHECK(no_of_rows<=3);



Now if you insert more than 3 rows in USERS_TABLE, you will face exception

تم تعديل بواسطة Mahmoud Ahmed El-Sayed

بتاريخ:

declare
v number
begin
select count(id) into v
if v>3 then
RAISE Form_Trigger_Failure;
end if

بتاريخ:

declare
v number
begin
select count(id) into v
if v>3 then
RAISE Form_Trigger_Failure;
end if


The questioner ask how to do it from database(trigger) not from oracle forms

بتاريخ:


declare
v number
begin
select count(id) into v
if v>3 then
RAISE Form_Trigger_Failure;
end if


The questioner ask how to do it from database(trigger) not from oracle forms





he did not determain to use it in sql or in forms

بتاريخ:

السادة / اعضاء المنتدى الكرام..............
لدى قاعة بيانات صغيرة , وأود عمل trigger او sql statement تقوم بعمل حد اقصى للصفوف (Rows) داخل جدول معين.
برجاء التكرم بالافادة للاهمية,,,,,,,, و شكرا,,,,,,,


The best solution to do this to create materialized view and create check constraint on materialize view



assume that your table as below

CREATE TABLE USERS_TABLE (USER_ID VARCHAR2 (50), USER_NAME VARCHAR2 (100));



then create below materialize view




CREATE MATERIALIZED VIEW LOG ON USERS_TABLE WITH ROWID(USER_ID) INCLUDING NEW VALUES;

CREATE MATERIALIZED VIEW mv
 REFRESH FAST
 ON COMMIT
AS
SELECT 1 dummy, COUNT(1)  no_of_rows
  FROM USERS_TABLE
 GROUP BY 1;




Now add check constraint to materialize view



ALTER TABLE MV ADD CONSTRAINT CHECK_MAX_USERS CHECK(no_of_rows<=3);



Now if you insert more than 3 rows in USERS_TABLE, you will face exception






declare
v number
begin
select count(id) into v
if v>3 then
RAISE Form_Trigger_Failure;
end if


The questioner ask how to do it from database(trigger) not from oracle forms





he did not determain to use it in sql or in forms



Please read #1 in post


وأود عمل trigger او sql statement تقوم بعمل حد اقصى للصفوف (Rows) داخل جدول معين

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

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

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

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

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

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.