当前位置:操作系统 > Unix/Linux >>

oralce自学(1)

oralce自学(1)
 
1.查询语句
 
[sql] 
select * from TF_B_TERM_PREPMG_LOG;  
  
  
select * from TD_M_TERM_PRICE;  
  
  
select * from TF_B_CEN_TERM_MANAGER_LOG,TF_B_CEN_TERM_MANAGER_DETAIL;    //两张表一起查  
  
  
select * from TF_B_CEN_TERM_MANAGER_DETAIL;  
  
  
select * from TF_B_CEN_TERM_MANAGER_LOG;  
  
  
select log_id*(1+0.1)newLog_id from  TF_B_CEN_TERM_MANAGER_LOG;      //将log_id上调10%展示出来,通过newlog_id展示出来  
  
  
select distinct log_id from TF_B_CEN_TERM_MANAGER_LOG;              //distinct :过滤掉关键字相同的数据  
  
  
select * from TF_B_CEN_TERM_MANAGER_LOG where log_id is null;            //查询条件是某个字段为null时,语句  
select * from TF_B_CEN_TERM_MANAGER_LOG where log_id is not null;  
  
  
select * from TF_B_CEN_TERM_MANAGER_LOG where log_id > 300 order by log_id ;     //order by 默认的是升序排列  
select * from TF_B_CEN_TERM_MANAGER_LOG where log_id > 300 order by log_id desc;    //order by 默认的是升序排列,如果需要降序排列,在后面加上desc  
select * from TF_B_CEN_TERM_MANAGER_LOG where log_id > 300 order by log_id,res_trade_id desc ;      //order by 可以带上多个参数排列,原则是排完第一个,在排序第二个  
  
  
//常用的函数  
select count(*) from TF_B_CEN_TERM_MANAGER_LOG;        //统计表中所有的记录数 count(*)  
select avg(log_id) from TF_B_CEN_TERM_MANAGER_LOG;    //统计表中字段的平均数 avg(keyword)   
select min(log_id) from TF_B_CEN_TERM_MANAGER_LOG;    //统计表中某个字段的最小值  
select max(log_id) from TF_B_CEN_TERM_MANAGER_LOG;     //统计表中某个字段的最大值  
select sum(log_id) from TF_B_CEN_TERM_MANAGER_LOG;     //统计表中某个字段的和  
  
  
select avg(log_id) from TF_B_CEN_TERM_MANAGER_LOG group by log_id;          //关联所有的logid相同的记录,通常和上面的几个函数一起使用  
select avg(log_id) from TF_B_CEN_TERM_MANAGER_LOG group by log_id having avg(log_id) > -1;     //having 语句通常和 group by 一起使用  

 

 
 
2.
 
[sql] 
create index index_name on table_name (cloumn_names);  
  
drop table table_name;    //删除表,表中的数据和索引等一并删除掉,oracle中的,以此表简历的视图,不会随着删除表而删除,但是使用的时候会报错  
  
drop view view_name;  
  
drop index index_name;  
  
                                                   //语句是没有问题,但是问题如下:  
                                                   //由于test 表巨大 估计有1亿  在增加 字段时 就不那么容易了,因为default 会锁表  
alter table test add nf_quota integer default 0;   //现在想问一下高手,是否可以对已有的记录 不指定缺省值,  
                                                   //对新增的记录指定缺省值,这样的语句该如何写?  
                                                   //这样的语句是否可以在巨型表上执行?  
                                                     
                                                     
alter table test drop column_name;  //如果表中只有一个字段,直接删除表                                             
                                                     
  
alter table test modify column_name long;  
   
alter table table_name rename to new_table_name;  
  
alter table table_name rename column_name to new_column_name;  

 

 
 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,