Thursday, 24 November 2011

interview question

how to find the first day of the current month of a given date

ANS:
declare
i date :='16-dec-11';
k varchar2(10);
j number;
begin
select to_number(to_char(i,'dd'))into j from dual;
if j<=15 then
select to_char(round(i,'month'),'day')into k from dual;
dbms_output.put_line(k);
else
select to_char(trunc(i,'month'),'day')into k from dual;
dbms_output.put_line(k);
end if;
end;

No comments:

Post a Comment