Oracle基本语句
来源:互联网 发布:图案设计软件 编辑:程序博客网 时间:2024/05/22 17:58
Oracle数据库基本语句:
假设有表job,有4个字段JOB,SKILL,LS,ID都为varchar类型
添加一行数据
insert into job (JOB,SKILL,LS,ID) values ('行长','领导','1’,'1'); //为job表添加一条数据,其中job为‘行长’,skill为‘领导’,ls为’1‘,id为’1‘
删除一行数据
delete from job where ID = '1'; //删除job表中id为’1‘的所有数据
去重查询
select distinct name from job //查询表job中name字段的不重复数据
假设有表job,有4个字段JOB,SKILL,LS,ID都为varchar类型
添加一行数据
insert into job (JOB,SKILL,LS,ID) values ('行长','领导','1’,'1'); //为job表添加一条数据,其中job为‘行长’,skill为‘领导’,ls为’1‘,id为’1‘
删除一行数据
delete from job where ID = '1'; //删除job表中id为’1‘的所有数据
去重查询
select distinct name from job //查询表job中name字段的不重复数据
修改一行数据
update job set JOB=’' where ID=''; //将job表中id为''数据的job字段更新为''
模糊查询
select * from job where job like '%航空%' //查询job表中job字段中含‘航空’的所有数据
修改表名
alter table job rename to work; //将表job改名为work
修改表中元素名
alter table job rename column skill to sky; //将job表中的skill字段改为sky
添加一个字段
alter table job add (c varchar2(50)) //为job表添加一个varchar类型,长度为50,名称为c的字段
删除一个字段
alter table job drop(c) //删除job表中名称为c的字段
联合查询(其中nine_ans,nine_score为表名,type,score,objid,num,ans为字段名)
select b.type, sum(b.score) as score
from nine_ans t,nine_score b
where t.objid='402881613a49410e013a4a8e7b89001e'
and t.num=b.num
and t.ans = b.seclection
group by type)
行转列 (使用pivot函数)
select * from (select b.type, sum(b.score) as score
from nine_ans t, nine_score b
where t.objid = '402881613a49410e013a4a8e7b89001e'
and t.num = b.num
and t.ans = b.seclection
group bytype)pivot(sum(score)for type in ('H' as H,'E' as E))
用于替换字段值docode函数
select decode(需要替换的字段名,需要替换的字段值,替换后的字段值,返回字段名)as 更换字段名可以不更换
select userid,name,sex,edu,tel,email,(select j.job from job j whereid = u.job) from userinfo u where usergroup in (select usergroupfrom admin where username like 'dm%')
update job set JOB=’' where ID=''; //将job表中id为''数据的job字段更新为''
模糊查询
select * from job where job like '%航空%' //查询job表中job字段中含‘航空’的所有数据
修改表名
alter table job rename to work; //将表job改名为work
修改表中元素名
alter table job rename column skill to sky; //将job表中的skill字段改为sky
添加一个字段
alter table job add (c varchar2(50)) //为job表添加一个varchar类型,长度为50,名称为c的字段
删除一个字段
alter table job drop(c) //删除job表中名称为c的字段
联合查询(其中nine_ans,nine_score为表名,type,score,objid,num,ans为字段名)
select b.type, sum(b.score) as score
from nine_ans t,nine_score b
where t.objid='402881613a49410e013a4a8e
and t.num=b.num
and t.ans = b.seclection
group by type)
行转列 (使用pivot函数)
select * from (select b.type, sum(b.score) as score
where t.objid = '402881613a49410e013a4a8e
and
and t.ans = b.seclection
group
用于替换字段值docode函数
select decode(需要替换的字段名,需要替换的字段值,替换后的字段值,返回字段名)
select userid,name,sex,edu,tel,email,(select j.job from job j whereid = u.job) from userinfo u where usergroup in (select usergroupfrom admin where username like 'dm%')
0 0
- oracle基本操作语句
- oracle DBA 基本语句
- oracle基本操作语句
- oracle基本语句学习
- Oracle 基本语句语法
- oracle基本语句
- Oracle 基本SQL语句
- oracle基本语句总结
- Oracle基本语句
- oracle基本语句
- oracle常用基本语句
- oracle基本操作语句
- oracle 基本语句
- Oracle基本SQL语句
- oracle基本SQL语句
- oracle 基本语句
- Oracle基本语句
- Oracle基本语句
- Codeforces Round #231 (Div. 2)A, B, C, D
- Xfire封装对象和List型对象
- C# 读取xml
- wince 禁止程序标题栏上的退出按钮X
- Mediastreamer2 library - a modular sound and video processing and streaming
- Oracle基本语句
- 浅谈JSP表单中的form传值
- 压哨大交易!格兰杰换特纳 东部谁还能挡步行者?
- WINCE 禁止MFC程序窗口上的OK按钮
- vim学习心得
- 九度OJ 1372 最大子向量和(连续子数组的最大和)
- java学习记录(二)字符串
- 九度1510(字符串)
- linux SIGFPE信号处理的疑惑