课堂笔记—Oarcle—01

1.数据库大致分类两种

1.关系型数据库(SQL)

Oracle、Mysql(80%)、DB2、Microsoft SQL Server、ProsgreSQL、Access、SQLSite

2.非关系型数据库(NoSQL = Not Only SQL)

MongoDB、Redis、HBASE、Cassandra

2.使用sqlplus连接Oracle数据库

1)在cmd中输入sqlpus /nolog

2)使用管理员账户登录recl数据库实例

conn sys/gzsxt@orcl as sysdba

3)解锁scott账户

alter user scott account unlock;

4)通过scott账户登录

conn scot/tiger@orcl

修改新的密码

新密码:tiger(输入时是不可见的)

确认新密码:tiger(输入时不可见的)

5)已连接

3.使用可视化工具,连接Oracle数据库

Username:scott :用户名

Password:tiger :密码

Database:ORCL

Connect as:Normal /使用什么角色登录

 

SQL(Structured Que Language)分类:

数据操纵语言DML(Data Manipulation Language)

select insert update delete

数据定义语言DDL(Data definition language)

create alter drop rename truncate

数据控制语言DCL(Data Control Language)

grant revoke

select 作用:检索“列”

select关键字第一个句型
select [列1,列2, ... ,列N] from  表    --从 表 中显示 列1,列2,列3

Oracle中,列名和表名默认不区分大小写,数据是区分大小写的,比如检索的内容

 

注意:

1.select后面的列可以起别名(查询的显示结果)

例子:select ename,sal,e.deptno from emp e,dept d;    --当存在多个表且列重名时可以使用表别名,但是需要在列前面加这个表别名(e.  d.)

1)列名后面一个空格后添加别名(别名中不许有“空格”)

2)列名后面一个空格后使用双引号添加别名

3)列名后面一个空格使用as 关键字,在as后面添加别名

2.distinct用于对显示结果去重复

1)distinct必须放在select后面

2)如果查询有多列,必须满足多列值都相同时,方可去重

 

from 作用:检索“表”

注意:检索的表后可以添加别名(别名不需要被双引号引起)

 

where 作用:过虑“行”记录(record)

用法:select * from emp where sal<3000;    --从emp表中 显示sal列数值小于3000的 所有行

 

例:显示emp表中员工姓名和年薪,sal为薪资列,ename为名字列
select ename,sal*12 年薪 from emp;    --这里的年薪为 列取的别名

使用distinct去除显示重复的结果

例子:查询emp表中job(工作)的种类

select distinct ename,job from emp;    --distinct只能放在select的后面,

 

1.=、!=、<>、<、>、<=、>=、any、some、all

例子:select * from emp where sal = 300;    --从emp表中 显示sal列数值等于3000的 所有行

2. is null、is not null

例子:select * from emp where sal is null;       --从emp表中 显示sal列为null'空'的 所有行

   例子:select * from emp where sal is not null ;    --从emp表中 显示sal列不为null'空'的 所有行

3.between x and y

例子:select * from emp where sal between 800 and 3000;    --从emp表中 显示sal列值为800-3000的 所有行

4.and、or、not

例子:select * frim where sal >=800 and sal <=3000 ;    --从emp表中 显示sal列数值大于等于800、小于等于3000的 所有行

例子:select *from where sal =800 and sal =3000;    --从emp表中 显示sal列等于800或者等于3000的 所有行

例子:select *from where sal is not null;    --从emp表中 显示sal列不为null'空'的 所有行

5.in(list)、not in(list)

例子:select * from emp where sal in (800,3000);    --从emp表中 显示sal列为800,3000的 所有行

例子:select * from emp where job not in ('MANAGER');    --从emp表中 过滤显示job列内容不为MANSGER(字符需要区分大小定)的 所有行

6.exists(子查询)、not exists(子查询)

例子:select * from emp where exisits( select * from dept where deptno != 50 );    --括号内子串返回false或true,外部则执行或不执行

例子:select * from emp where not exisits (select * from dept);    --括号内子串返回false或true,外部则反选或不执行(于上面相反)

7.like模糊查询

"%":匹配零个或若干个字符

"—":匹配一个字符

在模糊查询中,如果查询的数据中有“%”、“_”时,可以使用escape自定义字符

escape自定义字符:select * from emp where ename like '%a%%' escape'a' ;     --从emp表中 查询显示ename中含有%的 所有行,定义a为转义字符

例子:select * from emp where ename like '_M%' ;    --从emp表中 查询显示ename中第二个字母为M的 所有行

例子:select * from emp where ename like '%M_' ;   --从emp表中 查询显示ename中倒数第二个字母为M的 所有行

 

转载于:https://my.oschina.net/u/4118325/blog/3038117

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值