教程学院
图像设计 多媒体类 机械制图 办公软件 操作系统 系统编程 网站编程 网页制作 数据库类 网络路由 网络工程 网络安全 考试认证
firefox火狐浏览器下载
酷网学院
CAD
AutoCad Cam350 ProEngineer GCcam MATLAB Unigraphics SolidWorks CAXA Solid3000 Cimatron EdgeCAM
系统
安全 防火墙 病毒 WinXP Win2003 Vista
数据库
编程
网络
精彩图库
  当前位置: 库库中文网 · 数据库类教程 · Oracle教程 · Oracle综合技巧

Oracle培训教材

学院最新推荐文章
教程推荐
『Oracle培训教材』如果文章有大量图片,显示会较慢,请等待图片下载完成
 
点击数: 更新时间:2005-4-4 
金额

现有数据为:
200001  1000
200002  1100
200003  1200
200004  1300
200005  1400
200006  1500
200007  1600
200101  1100
200202  1200
200301  1300

想要转化为以下结构的数据:
year   char(4)      --年份
month1  number(10,2)   --1月销售金额
month2  number(10,2)   --2月销售金额
month3  number(10,2)   --3月销售金额
month4  number(10,2)   --4月销售金额
month5  number(10,2)   --5月销售金额
month6  number(10,2)   --6月销售金额
month7  number(10,2)   --7月销售金额
month8  number(10,2)   --8月销售金额
month9  number(10,2)   --9月销售金额
month10  number(10,2)   --10月销售金额
month11  number(10,2)   --11月销售金额
month12  number(10,2)   --12月销售金额

结构转化的SQL语句为:
create or replace view
v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12)
as
     select
     substrb(month,1,4),
     sum(decode(substrb(month,5,2),'01',sell,0)),
     sum(decode(substrb(month,5,2),'02',sell,0)),
     sum(decode(substrb(month,5,2),'03',sell,0)),
     sum(decode(substrb(month,5,2),'04',sell,0)),
     sum(decode(substrb(month,5,2),'05',sell,0)),
     sum(decode(substrb(month,5,2),'06',sell,0)),
     sum(decode(substrb(month,5,2),'07',sell,0)),
     sum(decode(substrb(month,5,2),'08',sell,0)),
     sum(decode(substrb(month,5,2),'09',sell,0)),
     sum(decode(substrb(month,5,2),'10',sell,0)),
     sum(decode(substrb(month,5,2),'11',sell,0)),
     sum(decode(substrb(month,5,2),'12',sell,0))
     from sale
     group by substrb(month,1,4);

四.NULL 使用详解
1. 含义解释:
问:什么是NULL?
答:在我们不知道具体有什么数据的时候,也即未知,可以用NULL,我们称它为空,ORACLE中,含有空值的表列长度为零。
ORACLE允许任何一种数据类型的字段为空,除了以下两种情况:
1、主键字段(primary key),
2、定义时已经加了NOT NULL限制条件的字段

说明:
1、等价于没有任何值、是未知数。
2、NULL与0、空字符串、空格都不同。
3、对空值做加、减、乘、除等运算操作,结果仍为空。
4、NULL的处理使用NVL函数。
5、比较时使用关键字用“is null”和“is not null”。
6、空值不能被索引,所以查询时有些符合条件的数据可能查不出来,count(*)中,用nvl(列名,0)处理后再查。
7、排序时比其他数据都大(索引默认是降序排列,小→大),所以NULL值总是排在最后。

2. 使用方法:
SQL> select 1 from dual where null=null;

没有查到记录

SQL> select 1 from dual where null='';

没有查到记录

SQL> select 1 from dual where ''='';

没有查到记录

SQL> select 1 from dual where null is null;

1

---------

1

SQL> select 1 from dual where nvl(null,0)=nvl(null,0);

1

---------

1

对空值做加、减、乘、除等运算操作,结果仍为空。

SQL> select 1+null from dual;

SQL> select 1-null from dual;

SQL> select 1*null from dual;

SQL> select 1/null from dual;

查询到一个记录.

注:这个记录就是SQL语句中的那个null

设置某些列为空值

update table1 set 列1=NULL where 列1 is not null;

现有一个商品销售表sale,表结构为:

month    char(6)      --月份

sell    number(10,2)   --月销售金额

create table sale (month char(6),sell number);

insert into sale values('200001',1000);

insert into sale values('200002',1100);

insert into sale values('200003',1200);

insert into sale values('200004',1300);

insert into sale values('200005',1400);

insert into sale values('200006',1500);

insert into sale values('200007',1600);

insert into sale values('200101',1100);

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页  

作者:无 来源:无
】【关闭窗口
·上页:
·下页:
相关文章
     数据库类教程 - Oracle综合技巧
普通教程Oracle 11g R1中大小写敏感地口
普通教程SQL Server与Oracle数据库在安全
普通教程Oracle 11g R1中AWR基线增强(1)
普通教程Oracle学习地一些建议
普通教程一步完成封装编译
普通教程Oracle Warehouse Builder 自动
普通教程Oracle 11gR1中表压缩增强
普通教程Oracle只希望红帽存在 其余Linu
普通教程Oracle中SQL语句执行效率地查询
普通教程Oracle 11gR1中地表空间加密
普通教程Oracle Wait Event:Data file i
普通教程Oracle 11gR1中地SecureFile(1)
精彩图片汇集
advertisement
关于站点 - 广告服务 - 联系我们 - 版权隐私 - 免责声明 - 合作伙伴 - 程序支持 - 网站地图 - 返回顶部
网站文本地图
版权所有:库库中文 2005-2007 欢迎各种媒体转载我们的原创作品[转载请注明出处]
copyright © 2005-2008 www.QQGB.com online services. all rights reserved. 蜀ICP备05015578
Template designed by Virus. Optimized for 1024x768 to Firefox,Opera and MS-IE6. Site powered by EQL.
红盾
热爱电脑,热爱生活
拥有电脑,拥有生命
让我们享受拥有电脑的时光