• Oracle 检索数据


    SELECT  *  |    {   [ DISTINCT  ]    column   |    expression   [   alias   ]  ,   ...    }

    FROM  table;


    •SELECT  标识 选择哪些列。
    •FROM    标识从哪个表中选择。


    column后面加上空格,同一时候跟上别名(alias),或者 as 别名。到下一行的内容时,要用逗号隔开。

    默认的别名是小写的。假设想要让它是大写的。使用 "别名"

    假设别名有多个单词的时候,用双引號别名的方式   比方 “annual  salary”

    select employee_id id, first_name name from employees;
    
    结果:

    .....

        193 Britney
        194 Samuel
         id NAME
    ------- --------------------
        195 Vance
        196 Alana
        197 Kevin
    107 rows selected



    连接符:

    •把列与列,列与字符连接在一起。

    •用 ‘||’表示。

    •能够用来‘合成’列。


    select last_name||' `s eamil is '||email from employees;

    类似于Java中的System.out.println(123+ “hello” + 123) ;//123hello123

    默认情况下。查询会返回所有行,包含反复行。


    SELECT last_name||' is a '||job_id 
           AS "Employee Details"
    FROM   employees;
    

    列的别名:

    •重命名一个列。
    •便于计算。
    •紧跟列名,也能够在列名和别名之间增加keyword‘AS’,别名使用双引號以便在别名中包括空格或特殊的字符并区分大写和小写
    SQL中仅仅有这儿用双引號(double quotation)

    SELECT last_name AS name,commission_pctcomm

    FROM   employees;

    SELECT last_name "Name", salary*12 "AnnualSalary"

    FROM  employees;


    The first example displays the names and the commission percentages of all the employees. Notice that theoptionalASkeyword has been used before the columnalias name. The result of the query is the same whether the AS keyword is used or not. Also notice that the SQL statement has the column aliases, name and comm, in lowercase, whereas the result of the querydisplays the column headings inuppercase. As mentioned in a previous slide, column headingsappear inuppercase by default.

    默认的这样的没有引號的别名是大写的

    Thesecond example displays the last names and annual salaries of all the employees.Because Annual Salarycontain a space, it has been enclosed in double quotation marks. Notice thatthe column heading in the output is exactly the same as the column alias.

    用双引號的这样的方式。能够将特殊的字符保留在引用的别名中。同一时候大写和小写和列的别名一致


    在SELECT子句中使用keyword‘DISTINCT’删除反复行。

    select distinct department_id from employees;
    DEPARTMENT_ID
    -------------
              100
               30
               20
               70
               90
              110
               50
               40
               80
               10
               60
    12 rows selected


    定义空值

    空值是无效的,未指定的,未知的或不可预知的值
    空值不是空格或者0。

    包括空值的数学表达式的值都为空值





    SQL 语句与 SQL*Plus命令

    Structural query language

    SQL

    一种语言
    ANSI 标准
    keyword不能缩写
    使用语句控制数据库中的表的定义信息和表中的数据


    SQL*Plus

    一种环境

    Oracle的特性之中的一个
    keyword能够缩写   desc employees,desc是sql plus的keyword,全称是describe;
    ed也是sql plus的keyword ,全称是edit
    命令不能改变数据库中的数据的值
    集中执行

    总结:

    1. 对于日期型数据, 做 *, / 运算不合法


    2. 包括空值的数学表达式的值都为空值


    3. 别名使用双引號!


    4. oracle 中连接字符串使用 "||", 而不是 java 中的 "+"


    5. 日期和字符仅仅能在单引號中出现. 输出 last_name`s email is email


    select last_name || ' `s email is ' || email EMAIL
    from employees


    6. distinct keyword, 下面语法错误


    select last_name, distinct department_id
    from employees

    习题:

     SQL*PLUS命令能够控制数据库吗?否!SQL*PLUS仅仅是一个执行环境,控制数据库的是SQL语言。



  • 相关阅读:
    vue基础八(路由组件)
    vue基础(七),同源策略以及跨域,vuex
    如何将注释的代码折叠
    axios发请求的基本语法:
    vue基础(六)全局事件总线
    vue基础(五),对todos的操作
    Android仿IOS的AssistiveTouch的控件EasyTouch实现
    CentOS下配置HTTPS访问主机并绑定访问端口号
    Effective Java:对于所有对象都通用的方法
    物联网操作系统HelloX开发者入门指南
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6768753.html
Copyright © 2020-2023  润新知