Oracle数据库之Oracle中的基本查询语句总结
小标 2018-11-19 来源 : 阅读 8521 评论 0

摘要:本文主要向大家介绍了Oracle数据库之Oracle中的基本查询语句总结,通过具体的内容向大家展现,希望对大家学习Oracle数据库有所帮助。

本文主要向大家介绍了Oracle数据库之Oracle中的基本查询语句总结,通过具体的内容向大家展现,希望对大家学习Oracle数据库有所帮助。


1.基本查询语句:

select [distinct] column_name1,.. from table_name where [conditions];

注:distinct关键字是为了去掉重复的记录


2.在sql/plus中设置格式

column column_name Heading new_name;

column column_name format dataformat;

column column clear;

例:col id heading 编号;


3.给字段设置别名

select colum_name as new_name,... from table_name ;


4.逻辑运算符的优先级:按照not、and、or的顺序依次递减

比较运算符的优先级高于逻辑运算符


5.模糊查询:like

通配符的使用:(,%)一个“”代表一个字符,%可以代表0到任意个字符。

例:select u.id,u.username from users u where username like '%b%';


6.范围查询

between..and..

例:select  from users where salary between 800 and 2000;

in/not in

例:select  from users where username in('aaa','bbb');


7.对查询结果排序:order by

select .. from table_name [where conditions] order by column_name desc/asc,...;

desc:降序 asc:升序

例:select id,username,salary from users where username not in('aaa','bbb') order by salary desc;


8.case...when语句的使用

Case column_name when values then result..[else result ]end;

例1:select username,case username when 'aaa' then '计算机部门'

2  when 'bbb' then '市场部门' else '其他部门' end as 部门

3  from users;


例2:select username,case when salary<=800 then '工资低'

2  when salary>5000 then '工资高' end as 工资水平

3  from users;


9.distinct可以去除多余的行,

如,查询员工信息表中的部门编号,要求去除重复数据:select distinct deptno from employee


10.使用as关键字设置字段别名的语法:select column_name as new_name,... from table_name;可以同时为多个字段设置别名。

使用column命令设置字段别名的语法:column column_name heading new_name,只能为一个字段设置别名。


11.decode函数的使用

decode(column_name,value1,result1,

...,defaultvalue)


二、操作表中的数据

1.插入语句;

insert into table_name (column1,column2,..) values(value1,value2,..);

例:insert into userinfo values(1,'xxx',123,..);

系统函数:sysdate//获取当前日期

注意:如皋添加的值为字符串类型,要加单引号


2.为表设置默认值

alter table userinfo modify email default '无';


3.复制表

在创建时复制

create table table_new as select column1... from table_old;

例子:create table userinfo_new   as select  from userinfo;

在插入数据时复制

insert into table_new [column1,...] as select * from table_old;


4.update语句

update table_name set column1=value1,... [where conditions];

例:update userinfo set userpwd='111',email='111@1126.com' where id=3;


5.删除表中的数据(记录)

delete from table_name [where conditions];

delete from userinfo whre id=2;

   

本文由职坐标整理并发布,希望对同学们学习Oracle有所帮助,更多内容请关注职坐标数据库Oracle数据库频道!


本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 35 不喜欢 | 6
看完这篇文章有何感觉?已经有41人表态,85%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程