Thursday, 24 November 2011

interview question

How to find the number of tables and total number of rows in a schema?

ANS:

Select count(table_name) totaltables,sum(num_rows) totalrows from user_tables;

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;