一些常用到的Oracle数据库操作
本文地址:http://www.jb51.cc/article/p-drgpesas-bpt.html
1 取出分组之后每组前多少条数据
select * from (select name,age row_number() over (partition by name order by age desc) rn from table_name) where rn <10
2 同组数据合并(数据行转列)
select name,wm_concat(distinct age) from (select name,age row_number() over (partition by name order by age desc) rn from table_name) group by name
3 奇数行
select name,age from (select rownum rn,name,age from table_name) where mod(rn,2) = 1;
4 复制表以及表中数据
create table table_name_new as select * from table_name;
-- table_name_new 表存在
insert into table_name_new select * from table_name;
commit;
5 查询表的全部字段及其个数
select wn_concat(column_name) from user_tab_cols where table_name=upper('表名');
select count(*) from user_tab_columns where table_name=upper('表名');