Oracle基本语句
2014-02-21 19:54
246 查看
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字段的不重复数据
修改一行数据
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%')
假设有表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%')
相关文章推荐
- oracle查询语句大全(oracle 基本命令大全一)
- oracle中scott用户下四个基本表SQL语句练习
- Oracle基本的SQL语句
- Oracle 10g数据库基础之基本查询语句-下-连接&子查询
- oracle基本操作语句
- Oracle中5个核心Sql语句的基本构造:Select、Insert、Update、Delete和Merge
- 数据库基本概念及Oracle基本语句
- oracle 基本查询语句及实例
- Oracle第一节 基本SQL SELECT语句
- SQL语句执行顺序以及oracle基本查询优化
- Oracle-基本SQL语句
- Oracle基本流程语句
- 有关MySQL数据库的一些基本语句和oracle数据的一些小区别-01
- oracle心得1--oracle简介@基本sql语句@条件查询@排序数据理论与案例
- 四、oracle基本sql语句和函数详解
- oracle 查询语句基本知识
- 回顾Oracle几个用到的基本语句
- oracle 基本语句
- oracle查询语句大全(oracle 基本命令大全一)
- Oracle 语句基础及基本操作。