Home » SQL & PL/SQL » SQL & PL/SQL » Help needed
Help needed [message #288163] Sat, 15 December 2007 03:51 Go to next message
world.apps
Messages: 70
Registered: January 2007
Location: Hyderabad
Member
Hi,

I am trying to compare the sarurday in if condition. But even I am getting saturday, if condition is not showing exact output.
This is my code. Even my output day is saturday, I am getting another day in the output. pls help me in this.

declare
v_check_date2 date;
v_day varchar2(25);
begin
v_check_date2:=next_day(LAST_DAY('05-jan-2008') -7, 'Saturday');
dbms_output.put_line(V_CHECK_DATE2);
v_day:=upper(to_char(v_check_date2,'day'));
dbms_output.put_line(v_day);
if (v_day='SATURDAY') then
dbms_output.put_line('saturday');
else
dbms_output.put_line('another day');
end if;
end;
SQL> /
26-JAN-08
SATURDAY
another day


Thanks in advance

[Updated on: Sat, 15 December 2007 03:55]

Report message to a moderator

Re: Help needed [message #288164 is a reply to message #288163] Sat, 15 December 2007 03:59 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
there are a couple of things:
1) '05-jan-2008' is not a date.its a string.use TO_DATE.
2) instead of to_char(v_check_date2,'day') because it will be padded by a space.
select length(to_char(sysdate,'day')) from dual
/
LENGTH(TO_CHAR(SYSDATE,'DAY')) 
------------------------------ 
9                              

1 rows selected

,so use
to_char(v_check_date2,'fmday').

regards,

[Updated on: Sat, 15 December 2007 03:59]

Report message to a moderator

Re: Help needed [message #288169 is a reply to message #288163] Sat, 15 December 2007 05:21 Go to previous message
world.apps
Messages: 70
Registered: January 2007
Location: Hyderabad
Member
Hi,

I got it.

Thanks
Previous Topic: length of SQL query
Next Topic: how can i do this procedure?
Goto Forum:
  


Current Time: Fri Dec 02 12:16:35 CST 2016

Total time taken to generate the page: 0.05957 seconds