plsql - Oracle weird behavior string comparison with day of the week -


while below code prints 'wrong thursday',(10-feb thursday)

begin   if to_char(to_date('10-feb-2011','dd-mon-yyyy'),'day')='thursday'     dbms_output.put_line('correct');    else     dbms_output.put_line('wrong '||to_char(to_date('10-feb-2011','dd-mon-yyyy'),'day'));   end if; end; 

the following prints 'correct',(09-feb wednesday)

begin   if to_char(to_date('09-feb-2011','dd-mon-yyyy'),'day')='wednesday'     dbms_output.put_line('correct');    else     dbms_output.put_line('wrong '||to_char(to_date('09-feb-2011','dd-mon-yyyy'),'day'));   end if; end; 

i've been trying figure out couldn't. appreciated. in advance.

to_char default space-padded:

sql> begin   2    dbms_output.put_line('x' ||   3                         to_char(to_date('10-feb-2011','dd-mon-yyyy'),'day')||   4                         'x');   5  end;   6  /  xthursday x 

use modifier fm prevent padding:

sql> begin   2    if to_char(to_date('10-feb-2011','dd-mon-yyyy'),'fmday')='thursday'   3      dbms_output.put_line('correct');   4    else   5      dbms_output.put_line('wrong '||to_char(to_date('10-feb-2011','dd-mon-yyyy'),'fmday'));   6    end if;   7  end;   8  /  correct  pl/sql procedure completed 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -