Saturday, August 18, 2012

write a function to return the count of rows in a table by passing table name as parameter......


create or replace function tab_count(p_table varchar2) return pls_integer
as
v_cnt pls_integer;
begin

execute immediate 'select count(1) from '||p_table into v_cnt;

return v_cnt;

end tab_count;
/

Swap YES,NO values in a table column with single update statement.....


update a set status=(case when status='YES' then 'NO'
  when status='NO' then 'YES'
end)

We can write select query in this way also....


select
(select count(*) from a),
(select count(*) from b),
(select count(*) from a,b)
from dual

How to get counts of first table ,second table and both tables in a join in single query?


select
(select count(*) from a),
(select count(*) from b),
(select count(*) from a,b)
from dual