一、Oracle SQL 基础

1. 认识SQL

SQL是什么?

SQL,结构化查询语言,全称是 Structured Query Language。

SQL 是一门 ANSI(American National Standards Institute 美国国家标准化组织)标准的计算机语言,但是仍然存在着多种不同版本的 SQL 语言。

PS:SQL对大小写不敏感,如select与SELECT是相同的

RDBMS 数据库程序

关系型数据库管理系统,全称 Relational Database Management System。(比如 MS Access、SQL Server、MySQL)


2. SQL基础语句

2.1 select (查询)

select * from 表名  --全量查询

select 列名1,列名2 from 表名  --查询指定列

select distinct 列名1 from 表名  --查询某列的唯一值

select t.rowid,t.* from 表名  --查询结果集可修改

2.2 where (条件子句)

=  --等于
<>  --不等于
>  --大于
<  --小于
>=  --大于等于
<=  --小于等于
between  --在某个范围内
like  --类似
in()  --指定某列的多个可能值

2.3 and&or (过滤子句)

and --且
or --或
select * from 表 where 列1=XXX and (列2=‘aaa’ or 列2=‘bbb’);

PS:结合起来使用的话要加上括号

2.4 order by (排序子句)

ASC  --默认,升序排列
DESC  --降序排列

PS: order by 多列时  先按第一列排序,第一列条件相同的基础下再对第二列进行排序

2.5 insert into (插入新记录)

insert into 表(列1,列2...) values (值1,值2...);

2.6 update(更新记录)

update 表 set 列=值 where 条件

2.7 delete (删除记录)

--删单/多条
delete from 表 where 条件

--删全部
delete from 表
delete * from 表
truncate table 表

转载自:有梦想的肥宅