oracle基础2

1.distinct 去掉重复数据

select distinct name from user;

排重只能写在字段的前面

select id,distinct name from user

sql语句前后语句必须保持一对一的关系

2.where查询

2.1 where 限制表中的行的数据返回的,满足条件的数据被选中,不满足条件的数据被选中

2.2语法

select 字段名 from 表名 where 条件

1=1 真

1!=1假

2.3.SQL中数学运算符有哪些

=    ,!= , >  ,< , >= ,<=

2.4.SQL提供的运算符

a.sql中表达一个闭区间 [a,b]

b.表示一个值处在一个列表的范围内

select * from user where id in(1,2,3);

c.空值的判断运算符

is null

d.模糊查询 运算符like

%代表 0-n个任意字符串

_代表一个字符串

select * from user where name like "_a"          查询name的第二个字符为a的数据

select * from user where name llike "%a%"    查询name中带a的数据

2.5 逻辑运算符

  与    &&  等同于  and

  或   || 等同于  or

  非

  = !  =

  >     <=

       <     >=

  between a and b  not between a and b

  in            not in

  like          not like

  is null       is not null

2.6条件的优先级 使用小括号解决

3.排序

3.1按照一定的标准 把数据按照一定的顺序(升序和降序)排列

3.2 语法

select 字段名 from 表名 where 条件 order by 排序标准 排序方式

3.3排序方式

升序 asc

降序 desc

4.单行函数

 upper(par1) 字符串变成大写

lower(par1)把字符串变成小写

length(par1)求字符串的长度

initcap(par1)把每个单词的首字母变成大写

length(par1)求字符串的长度

concat(par1,par2)连接两个字符串并返回

subtr(par1,par2,par3)截取字符串 

  par1是要截取的字符串

  par2,是截取的位置 编号从一开始,负一代表最后一个字符

  par3 代表截取的字符串的长度

格式化显示函数

to_char(param1,param2)

param1 原始的字符串

param2 格式化以后的字符串

round(param1,param2)四舍五入函数 param2表示显示的精度

trunc(param1,param2) 截取函数

猜你喜欢

转载自www.cnblogs.com/liyanzi/p/12187202.html