目录
1、简单查询
2、查询某个字段
3、条件查询
4、查询不重复的值
5、多条件查询
6、升序降序查询
7、为空或者不为空查询
8、模糊查询
9、包含查询
10、两个值之间的数据查询
--注释:table_name为表名 a为别名。
--直接查询某个表 用select * from语句
select * from table_name;
--查询某个字段 将* 替换成字段名
select a.id from table_name a;
--查询一个表中的几个字段 之间用 ‘,’ 连接
select a.id,a.code,a.address from table_name a;
--查询某个字段中唯一、不重复的值 用distinct进行查询
select distinct a.address from table_name a;
--依据条件查询 用where 筛选条件。例如:下文中的查询表中的code字段为’0331‘的相关信息
select * from table_name a where a.code='0331';
--多条件查询相关的信息 用and连接
select * from table_name a where a.code='0331816900' and a.is_valid=1;
--依据其中一个条件 用or连接
select * from table_name a where a.code='0331816900' or a.is_valid=1;
--依据表中的某个字段升序排序查询 用’order by‘ 在 ’order by‘后面接字段名
select * from table_name order by code;
--依据某个字段降序排序查询 用 'order by 字段名 desc'
select * from table_name order by code desc;
--查询某个字段不为空 在字段后面添加‘is not null’
select * from table_name a where a.is_valid is not null;
--查询某个字段为空 在需要查询的字段后面添加'is null'
select * from table_name a where a.is_valid is null;
--模糊查询 在字段后添加 'like' , '春%'查询‘春’字开头的信息 '%春%'查询包含所有的‘春’字的信息
select * from table_name a where a.address like '%春%';
--依据某个字段的特定值查询 用 ‘in’ 包含特定查询的值
select * from table_name a where a.address in ('五龙家园二期38-1-501','泰兴镇泰兴里2-1-201');
--依据字段之间所有的值 查询某个值到某个值之间的所有信息用 ‘between 指定信息 and 指定信息’
select * from table_name a where a.code between 03318 and 05514;
这都是在Oracle中常见的查询,如有不对欢迎批评指正。