الانتقال إلى المحتوى

كيف استخرج اكبر رقم بدون استخدام دالة max


المجازف

Recommended Posts

الله لايمسيكم الا بالخير

اخواني الاوراكليون

انا قدر الله علي وغبت محاضر وحيده وكانت هالمحاضره مفتاح كل حاجه

طبعا الدكتور عطانا واجب يقول انشئ جدول فيه عمود واحد فقط اسمه id

ادخل 50 رقم وطلع لي اكبر رقم بدون استخدام دالة max

يجب استخدام while loop

طبعا الكود تكتبون كذا

declare

begin

end


وخالص شكري وتقديري وامتناني لكم مقدماً

اخوكم المجازف

رابط هذا التعليق
شارك

السلام عليكم...
هذه بعض الحلول,أعتقد أن الحل الثالث يفي بالغرض....بالتوفيق

declare
Pmax number:=0;
Pmin number:=0;
cursor cur is select ID from test; begin for rec in cur loop
if rec.ID>Pmax then Pmax:=rec.ID;end if;
if rec.ID <Pmin then Pmin:=rec.ID;end if;
end loop;
dbms_output.put_line(Pmax);
dbms_output.put_line(Pmin);
end;
/



declare
Pmax number:=0;
cursor cur is select ID from test order by ID desc;
begin open cur;
fetch cur into Pmax; close cur;
dbms_output.put_line(Pmax);
end;
/



declare
Pmax number:=0;
Pcurrent number:=0;
cursor cur is select ID from test; begin open cur;
fetch cur into Pcurrent; while cur%found loop
if Pcurrent>Pmax then Pmax:=Pcurrent;end if;
fetch cur into Pcurrent; end loop;
close cur;
dbms_output.put_line(Pmax);
end;
/
رابط هذا التعليق
شارك

السلام عليكم...
لقد لا حظت أن هناك خطأ في الحل الأول لأن عملية المقارنة لأول مرة يجب أن تتم مع أحد نتائج الكيرسر و ليس مع الصفر لذلك يصبح الحل:

declare
Pmax number:=0;
Pmin number:=0;
f boolean:=false;
cursor cur is select ID from test; begin for rec in cur loop
if not f then Pmax:=rec.ID;Pmin:=rec.ID;f:=true; end if;
if rec.ID>Pmax then Pmax:=rec.ID;end if;
if rec.ID<Pmin then Pmin:=rec.ID;end if;
end loop;
dbms_output.put_line(Pmax);
dbms_output.put_line(Pmin);
end;
/
رابط هذا التعليق
شارك

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

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

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

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

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

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