关于oracle的相关基础语句
----给表的字段添加描述
COMMENT ON COLUMN 数据库名称.表名.表字段 IS '字段描述';
---设置自动增长
CREATE SEQUENCE emp_sequence
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
NOCACHE -- 不建缓冲区
------给表增加一个字段
alter table 表名 add 字段名 数据类型(类型长度);
------给表的某个字段设置默认值
update GOODSINFO set GOODSINFO.ISBATCH=1;
----删除表中的某个字段
ALTER TABLE 表名称 DROP COLUMN 删除的字段名称;
----删除表
drop table 表名
---修改字段类型
alter table tb modify (name nvarchar2(20));
----创建视图
create view V_GOODSINFO as 查询语句
---给字段0和1设置名字
select u.id,u.realname,U.SEX,
( case u.sex
when 1 then '男'
when 2 then '女'
else '空的'
END
) 性别
from users
u;
---按月分组
select to_char(exportDate,'yyyy-mm'),sum(amount) from table1 group
by to_char(exportDate,'yyyy-mm')
--按季度分组
select to_char(exportDate,'yyyy-Q'),sum(amount) from table1 group
by to_char(exportDate,'yyyy-Q')
--按年分组
select to_char(exportDate,'yyyy'),sum(amount) from table1 group by
to_char(exportDate,'yyyy');
--按月份统计分组
select
b.MATERIALname, --商品名称
b.GOODSPEC, -- 规格
b.SAFETYONE, --编码
a.OUTOFSTORAGETYPE, --出入库类型
sum(a.INNUM), --入库总数
sum(a.OUTNUM), --出库总数
sum(((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID) * a.INNUM)) as inmoney, --入库总金额
sum(((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID) * a.OUTNUM)) as outmoney, --出库总金额
to_char(a.CREDATE,'yyyy-mm')
from UNMATERIAL_Order a ,UNMATERIAL b
where to_char(a.CREDATE,'yyyy')=to_char(sysdate,'yyyy') and a.MATERIAL_id = b.MATERIAL_id
group by to_char(a.CREDATE,'yyyy-mm'),b.MATERIALname,b.GOODSPEC,b.SAFETYONE,a.OUTOFSTORAGETYPE
---- 将 数量、金额、根据十二个月进行统计
select
b.MATERIALname, --商品名称
b.GOODSPEC, -- 规格
b.SAFETYONE, --编码
a.UNMATERIAL_ID,
sum(decode(to_char(a.CREDATE,'mm'),'01',a.INNUM,0)) INNUM1,
sum(decode(to_char(a.CREDATE,'mm'),'02',a.INNUM,0)) INNUM2,
sum(decode(to_char(a.CREDATE,'mm'),'03',a.INNUM,0)) INNUM3,
sum(decode(to_char(a.CREDATE,'mm'),'04',a.INNUM,0)) INNUM4,
sum(decode(to_char(a.CREDATE,'mm'),'05',a.INNUM,0)) INNUM5,
sum(decode(to_char(a.CREDATE,'mm'),'06',a.INNUM,0)) INNUM6,
sum(decode(to_char(a.CREDATE,'mm'),'07',a.INNUM,0)) INNUM7,
sum(decode(to_char(a.CREDATE,'mm'),'08',a.INNUM,0)) INNUM8,
sum(decode(to_char(a.CREDATE,'mm'),'09',a.INNUM,0)) INNUM9,
sum(decode(to_char(a.CREDATE,'mm'),'10',a.INNUM,0)) INNUM10,
sum(decode(to_char(a.CREDATE,'mm'),'11',a.INNUM,0)) INNUM11,
sum(decode(to_char(a.CREDATE,'mm'),'12',a.INNUM,0)) INNUM12,
sum(decode(to_char(a.CREDATE,'mm'),'01',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY1,
sum(decode(to_char(a.CREDATE,'mm'),'02',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY2,
sum(decode(to_char(a.CREDATE,'mm'),'03',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY3,
sum(decode(to_char(a.CREDATE,'mm'),'04',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY4,
sum(decode(to_char(a.CREDATE,'mm'),'05',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY5,
sum(decode(to_char(a.CREDATE,'mm'),'06',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY6,
sum(decode(to_char(a.CREDATE,'mm'),'07',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY7,
sum(decode(to_char(a.CREDATE,'mm'),'08',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY8,
sum(decode(to_char(a.CREDATE,'mm'),'09',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY9,
sum(decode(to_char(a.CREDATE,'mm'),'10',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY10,
sum(decode(to_char(a.CREDATE,'mm'),'11',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY11,
sum(decode(to_char(a.CREDATE,'mm'),'12',((select APRICE from UNMATERIAL where KEYID=a.MATERIAL_ID)* a.INNUM),0)) INMONEY12
from UNMATERIAL_Order a ,UNMATERIAL b
where to_char(a.CREDATE,'yyyy')=to_char(sysdate,'yyyy') and a.MATERIAL_id = b.MATERIAL_id and a.OUTOFSTORAGETYPE='入库'
group by to_char(a.CREDATE,'yyyy-mm'),b.MATERIALname,b.GOODSPEC,b.SAFETYONE,a.UNMATERIAL_ID
关于oracle的相关基础语句的更多相关文章
- 【RAC】RAC相关基础知识
[RAC]RAC相关基础知识 1.CRS简介 从Oracle 10G开始,oracle引进一套完整的集群管理解决方案—-Cluster-Ready Services,它包括集群连通性.消息和锁. ...
- JAVA相关基础知识
JAVA相关基础知识 1.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分, ...
- Linux 相关基础笔记
html,body { } .CodeMirror { height: auto } .CodeMirror-scroll { } .CodeMirror-lines { padding: 4px 0 ...
- linux设备驱动归纳总结(二):模块的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59415.html linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10 ...
- linux设备驱动归纳总结(一)内核的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59413.html linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxx ...
- Oracle 性能相关常用脚本(SQL)
在缺乏的可视化工具来监控数据库性能的情形下,常用的脚本就派上用场了,下面提供几个关于Oracle性能相关的脚本供大家参考.以下脚本均在Oracle 10g测试通过,Oracle 11g可能要做相应调整 ...
- Oracle Applications DBA 基础(一)
1.引子 2014年9月13日 20:33 <oracle Applications DBA 基础>介绍Oracle Applications R12的系统架构, 数据库后台及应用系统的基 ...
- Oracle数据库操作---基础使用(二)
此篇承接上一篇的基本原理,继续展开学习,本篇主要面向数据的使用和管理,也就是开发者常用的基础语句,开始喽…… >>>对整表的操作 >创建表 关键字 Create creat ...
- Oracle数据库,基础知识
1.Oracle的五大约束条件: 1 主键 primary key2 外键 foreign key,3 唯一 unique,4 检测 check5 非空 not null 实例运用: -- ...
随机推荐
- 使用HTML5+CSS3制作圆角内发光按钮----示例
<!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...
- iOS UITableViewCell 中 调整imageView 的图片大小
在我的项目中,很多地方都希望将UITableViewCell 中的imageView 能根据自己图片的大小来进行展示,而就为了解决这个问题又觉得重写UITableViewCell 很不值得. 如下: ...
- 三部曲二(基本算法、动态规划、搜索)-1004-Instant Complexity
Instant Complexity Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- HDU 1508 DP
题意:规定一个数列 = {这个数的质因子只能包括2,3,5,7},求第n个数字是多少: 思路:暴力打表,然后只粘数据,虽然过了,但是正解其实是DP,每一个数字都是由某一个该数列里的某一个数字乘以2,3 ...
- SQL 变量
1.变量可以暂时储存数据 --定义变量: declare @xxx int --变量赋值: set @xxx=1 select @xxx=3 --变量的使用: print @xxx 2.--全 ...
- leetcode52. N-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- maven web project打包为war包,目录结构的变化
一个maven web project工程目录: 资源管理器中的目录层级如下: 导出为war包之后的目录层级为: 我们会发现,其实并没有如下的这些目录层级: 所以这两个目录层级只是IDE为我们添加的, ...
- python 深拷贝与浅拷贝
浅拷贝的方式有: lst=[1,2,3] (1)直接赋值: lst_cp = lst (2)for循环遍历生成:lst_cp= [i for i in lst] (3)copy模块下,copy.cop ...
- Lintcode Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16 ...
- 关于Mac下的SSH客户端iterm2等配置
linux后台开发的同学们晓得,在windows下有xshell\securecrt这样优秀的ssh客户端软件.mac下查找了下,有securecrt mac版,网上也有破解的,试用了一段时间,一个问 ...