查询a表中的所有数据
select * from a;
查询指定列的数据
select 列名1,列名2 from 表名;
||连接符,将多个列连接起来
select 列名1||列名2 from 表名;
条件查询
查询Email为空的用户信息
select * from 表名 where Email is null;
查询Email不为空的用户信息
select * from 表名 where Email is not null;
精确查找
select * from tablename where 列名='xxx';
模糊查询
select * from tablename where user_id like 'z%'; %表示0到多个字符
select * from tablename where user_id like '_m'; _表示一个字符
去重 关键字distinct
select distinct 列名1,列名2 from tablename
常用数据类型
CHAR(size)固定长度字符串类型,长度为size个字节,size最大为2000,最小值和默认值都为1
VARCHAR2(size)可变长度字符串类型,长度size个字节,size最大为4000,最小值为1,必须指定一个VARCHAR2的size
NUMBER(size)数值有效位数为size的值
NUMBER(p,s)p为总有效数据位数,取值范围38,默认38,可以用*代替。s为小数位数,取值范围-84~127,默认值取决于p,没有指定p,则s为最大范围,指定p,则s=0
date日期类型
多条件查询 or/and/in()/between...and.../not()
select * from tablename where 列名1='xxx' and 列名2='xxx';
select * from tablename where 列名1='xxx' or 列名2='xxx';
select * from tablename where name in('张三','里斯','王五');
select * from tablename where name not in('张三','里斯','王五');
左外连接 select * from [表名1] left join [表名2] where [过滤条件]
右外连接 select * from [表名1] right join [表名2] where [过滤条件]
全连接 select * from 表名1 a full join 表名2 b where [过滤条件]
内连接 select * from X a inner join Y b where a.列1 = b. 列2