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

تابع ملا حظات لمبرمجي اوراكل


سالم الفروي

Recommended Posts

3 - انتيه للدالة to_char
لاحظ المثال التالي


  SQL> set serveroutput on
    SQL> declare
      2      dob_month number(2) := 6;
      3      dob_day   number(2) := 6;
      4      dob_year  number(4) := 1960;
      5      --
      6      hold_dob  varchar2(8) := '06061960';
      7  begin
      8      if to_char (dob_month,  '09') = substr (hold_dob, 1, 2) and
      9         to_char (dob_day,    '09') = substr (hold_dob, 3, 2) and
     10         to_char (dob_year, '9999') = substr (hold_dob, 5, 4) then
     11             dbms_output.put_line ('Y');
     12      else
     13          dbms_output.put_line ('N');
     14      end if;
     15      --
     16      if dob_month = to_number (substr (hold_dob, 1, 2), '99')   and
     17         dob_day   = to_number (substr (hold_dob, 3, 2), '99')   and
     18         dob_year  = to_number (substr (hold_dob, 5, 4), '9999') then
     19             dbms_output.put_line ('Y');
     20      else
     21          dbms_output.put_line ('N');
     22      end if;
     23  end;
     24  .
    SQL> /
    N
    Y

    PL/SQL procedure successfully completed.

    SQL>






و السبب ان الشرط الاول اعطى النتيجة n لان الدالة to_char تضيف فراغ space للارقام الموجبة
فمثلا ('To_char (6, '09 تعطي النتيجة "09 " . لاحظ زيادة الفراغ في البداية .وبالتالي كانت نتيجة الشرط false

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

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

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

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

×   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.

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

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

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