【数据库】Oracle数据库学习笔记

Oracle数据库

[!tip]
当我们学习一个新知识的时候,往往是先学会怎么用,然后再使用的过程中慢慢理解原理,这样也许不失为一种高效的学习方式

数据库语言的分类

数据库语言一般分为四种

  • DDL:数据库定义语言:create、drop
  • DML:数据库操作语言:insert、update、delete
  • DQL:数据库查询语言:select
  • DCL:数据库控制语言:grant、revoke

[!warning]
在数据库语言中,对大小写是不敏感的

Select语句的用法

select column1,column2 from table1; //查询表中某几个列的数据
select * from table2; //查询表中所有列的数据

Order by子句

select * from table1 order by id ASC; //查询结果根据id排序,其中ASC表示升序,DESC表示降序(不加ASC也默认是升序)
select * from table1 order by id ASC NULLS FIRST;//如果出现了null,就将所有带有null的放到前面

Distinct子句

select distinct column1 from table1; //过滤掉了column1中重复项后输出

Where子句

select * from table1 where id = 1; //查询id为1的数据
select * from table2 where id = 1 and column1 = 'alice'; //查询id为1并且某一列是alice的数据
select * from table3 where id between 10 and 60; //查询id在10到60之间的数据
select * from table3 where id in(1,3); //查询id为1或者id为3的数据
select * from table4 where column1 like 'alic%'; //%是一个通配符,查询column1中值为alic开头的数据

And和Or子句

  • And子句在上面介绍过,表示两个条件同时满足
  • Or字句表示两个条件满足一个即可
  • 二者可以结合使用,可以多次使用

Fetch子句

FETCH 子句在 Oracle 中可以用来限制查询返回的行数,但仅能在12c以上版本使用

select * from table1 order by score fetch next 5 rows only; //获取前五行内容,其中的 next ... rows 可以替换为 first ... row
select * from table2 order by score fetch next 5 rows with ties; //如果前五行之后有并列第五的,也会包含在内
select * from table3 order by score fetch next 5 percent rows only; //查询前5%
select * from table4 order by score offset 10 rows fetch next 5 rows; //跳过前10之后的五行,实际上是11~15行

In子句

基本用法上面已经介绍过了,这里说明一下还可用not in 以及执行子子语句

select * from table1 where id in(
    select id from table1 where column1 = 'alice'
); //先执行里面的语句筛选出id,然后再进行外部的查询,查找id在in的范围里面的数据

Like子句

前面已经有过样例了,这里介绍几个通配符

  • % 代表0个或多个字符 alic%
  • _ 代表一个字符 alic_
  • [charlist] 字符表中的任意一个字符 [abc]lice 搜索alice blice clice
  • [!charlist]或者[^charlist] 不在字符表中的任何一个字符 [ab] 排除alice blice

相关推荐

  1. 数据库Oracle数据库学习笔记

    2024-04-28 14:36:04       35 阅读
  2. 如何快速学习 Oracle 数据库

    2024-04-28 14:36:04       23 阅读
  3. Oracle数据库

    2024-04-28 14:36:04       47 阅读
  4. 学习笔记数据库)1

    2024-04-28 14:36:04       20 阅读
  5. OracleOracle数据库中的数据类型

    2024-04-28 14:36:04       21 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-28 14:36:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-28 14:36:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-28 14:36:04       82 阅读
  4. Python语言-面向对象

    2024-04-28 14:36:04       91 阅读

热门阅读

  1. 人工智能底层自行实现篇3——逻辑回归(上)

    2024-04-28 14:36:04       37 阅读
  2. php视图处理类

    2024-04-28 14:36:04       31 阅读
  3. Flink 实时数仓(二)【ODS 层开发】

    2024-04-28 14:36:04       33 阅读
  4. 旅游景区一体化污水处理设备产品特点

    2024-04-28 14:36:04       32 阅读
  5. 模拟LinkedList实现的双向链表

    2024-04-28 14:36:04       30 阅读
  6. 【论文浅尝】LLM as a System Service on Mobile Devices

    2024-04-28 14:36:04       34 阅读
  7. 使用H5+app在安卓5.1离线环境实现文字转语音

    2024-04-28 14:36:04       31 阅读
  8. 数学与机器学习:共舞于智能时代的双璧

    2024-04-28 14:36:04       29 阅读
  9. 数据结构(并查集,ST表)

    2024-04-28 14:36:04       33 阅读