1 2 Previous Next 15 Replies Latest reply: Nov 14, 2012 2:38 AM by Billy~Verreynne Go to original post RSS
      • 15. Re: function compiled with error
        Billy~Verreynne
        Horrible code.

        Why use string functions when date functions are available?

        Again - why use SQL to run functions available in PL/SQL, to perform a calculation (possible in PL/SQL), to assign a value to a PL/SQL variable?

        Would you use a call to a Java stored proc to increment a PL/SQL variable with 1? Then why use SQL to do something to a PL/SQL variable that PL/SQL is perfectly capable of doing?

        Example:
        // truncate date to year (Jan), add 1 month (Feb) and determine if the
        // last day is the 29th
        SQL> create or replace function isLeapYear( d date ) return boolean is
          2  begin
          3          return(
          4                  extract( day from last_day( add_months( trunc(d,'yyyy'), 1 ) )) = 29
          5          );
          6  end;
          7  /
        
        Function created.
        
        SQL> 
        SQL> exec if isLeapYear(sysdate) then dbms_output.put_line('true'); else dbms_output.put_line('false'); end if;
        true
        
        PL/SQL procedure successfully completed.
        
        SQL> 
        1 2 Previous Next