Oracle

SELECT语句

单表查询

  1. SELECT Column1, Column2
  2. from table1

多表连接查询

  1. SELECT table1.Column1,table2.Column2
  2. from table1,table2

对选择可运算的列进行运算操作

  1. select salary, salary * 2
  2. from employees

image.png

NULL

NULL表示 不可用、未赋值、不知道、不适用,它既不是0 也不是空格。

给查询的列起别名

  1. select last_name
  2. AS name, employee_id id
  3. from employees

image.png

  1. select last_name AS "Name", salary * 2 "Annual Salary"
  2. from employees

image.png

字符串连接操作符

  1. SELECT last_name, job_id AS "Employees"
  2. FROM employees;

image.png

  1. SELECT last_name||job_id AS "Employees"
  2. FROM employees;

image.png

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

image.png

DISTINCT去除重复行

默认情况,返回所有行,包括重复行

  1. SELECT department_id
  2. FROM employees;

image.png

使用DISTINCT消除重复结果行

  1. SELECT DISTINCT department_id
  2. FROM employees;

image.png