Oracle - 简单的 SELECT 的使用

简介: Oracle - SELECT 及过滤和排序一、SELECT的基本使用> 查询返回所有数据:select * from tablename;> 查询返回一部分字段:select 字段1,字段2 from tablename;> 列的别...
Oracle -  SELECT 及过滤和排序

一、SELECT的基本使用
> 查询返回所有数据:select * from tablename;
> 查询返回一部分字段:select 字段1,字段2 from tablename;

> 列的别名一般用双引号,以便在别名中包含空格或特殊字符,别名的写法有两种方式:
    > 紧跟在字段(列)后面
       select 字段a a_name,字段b from tablename;
       select 字段a “a name”,字段b from tablename;
    > 在列名和别名之间加入关键字 ‘as’
       select 字段a as a_name,字段b from tablename;
    > 字符串用单引号 ' ' 来连接,只有在取别名时,才会用双引号 ""

> 连接符:把列与列连接在一起,用 '||' 表示,可以用来合成列
   select last_name || ' `s job_id is ' || job_id from employees;

> 去除重复:使用关键字 ‘distinct’
   select distinct 字段a from employees;  去除字段 a 重复的数据

> 显示表的结构:使用 desc[ribe] tablename;

二、在查询中过滤行
> 常用的比较运算符:等于(=)、不等于(!= 或 <>)、大于(>)、大于等于(>=)、小于(<)、小于等于(<=)
> 其他比较运算符:
    > 在两个值之间,包含边界(between ... and ...):
        > select * from tablename where id between 10 and 100;
    > 等于值列表中的一个( in(set) )
        > select * from tablename where id in(10, 20, 30);
    > 模糊查询(like),使用like运算选择类似的值,选择条件可以包含字符或数字:
        > % 代表零个或多个字符(任意个字符)
        > _  代表一个不确定的字符(比如he_lo,表示第三个字符是不固定的,其他是固定的)
        > select * from tablename where name like ' he_llo % ' ;
    > 空值(is null)
        > select * from tablename where id is null;  
        > select * from tablename where id is not null;
    > 回避特殊符号(escape) :使用转义符
        > select * from tablename where id like ' IT\_% ' escape ' \ ' ;

> 使用 where 子句,将不满足条件的行过滤
     > 带单条件的查询:select * from tablename where id>=10;
    > 带多条件的查询:select * from tablename where id>=10 and  id < 100; // and(且)、or(或)、否(not)
    > 查询时,字符和日期要包含在单引号 ( ' ' ) 中,日期格式敏感,默认的格式是:DD-MON月-RR

三、在查询中排序
> 使用 order by 排序,order by 子句在select语句的结尾
    > asc (ascend):升序                desc(descend):降序
    > select * from tablename order by id; // 默认对 id 字段升序排列
    > select * from tablename order by id desc; // 对 id 字段降序排列
相关文章
|
SQL Oracle 关系型数据库
MySQL 和 Oracle 中的 SQL SELECT TOP 是等价的
MySQL 和 Oracle 中的 SQL SELECT TOP 是等价的
91 0
|
SQL Oracle 关系型数据库
oracle学习51-select t.*,t.rowid
oracle学习51-select t.*,t.rowid
158 0
|
Oracle 关系型数据库
Oracle中select语句过滤和排序数据
简要介绍Oracle中select语句过滤和排序数据,并附操作实例
|
Oracle 关系型数据库 Linux
Linux系统中Oracle数据库使用SELECT语句检索数据(1)实例应用
1,首先切换到Oracle用户,并进入数据库#sql / as sysdba2,启动数据库,并连接样例及表格,启动命令#startup,连接样例#conn scott/tiger3,select语句中:不区分大小写;可以写一行或多行,为方便查看最好每个子句单独一行;语句以“;”结尾结束语句4,se.
|
Web App开发 Oracle 关系型数据库
|
SQL Oracle 关系型数据库
Oracle:使用SQL SELECT语句检索数据
一、官档 Book → SQL Language Reference → 19 SQL Statements: SAVEPOINT to UPDATE → SELECT 二、基础语法 SELECT {[distinct]列名,列名,…}|* FROM 表名 [WHERE 条件] [GROUP BY 分组列名] [HAVING 聚合函数] [ORDER BY 排序列名 ASC|DESC] 三、符号 单引号('):在Oracle中,应该只使用单引号将文本和字符和日期括起来,不能使用引号(包括单双引号)将数字括起来。
1586 0

推荐镜像

更多