-- number(38)
-- char(2000)
-- varchar(4000) create table student(
sno number(3) primary key,
sname varchar2(40) default ('佚名'),
sex char(2) check(sex in('男', '女', '中')),
age number(2) check( age between 20 and 30 ),
birthday date,
sclass varchar2(10)
); -- insert delete update
-- 事务: 一组相关的操作
-- commit 提交事务
-- rollback 回滚事务 -- 添加数据
-- 格式1: insert into 表 values(所有列的值); insert into stuinsert into student values(1, 'jack', '男', 23, null, 'ab11');dent values(1, 'jack', '男', 23, null, 'ab11');
insert into student values(2, 'tom', '男', 21, null, 'ab12');
commit; -- 格式2: insert into 表(指定列) values(指定列的值);
insert into student(sno, sname, birthday) values(3, 'mary', '7-7月-2017');
insert into student(sno, sname, birthday) values(4, 'mary', to_date('2017-06-10', 'yyyy-mm-dd'));
commit; select * from student; -- 修改数据 update
-- 格式: update 表 set 列=新值,... [where clause] -- 把吴丹阳的年龄减小2岁,手机号改为13888888888
update studentinfo set s_age = s_age - 2, s_tel = '13888888888' where s_name = '吴丹阳';
commit; select * from studentinfo s;
-- 删除数据 delete
-- 格式: delete from 表 [where clause] -- 删除吴丹阳的学生信息
delete from studentinfo where s_name = '吴丹阳';
commit; -- 查询数据 select
-- select 列 from 表 [where clause];
select * from classinfo c;
select * from studentinfo s;
select * from teacherinfo t; -- 查询年龄大于23岁的男生的信息
select * from studentinfo s where s.s_age > 23 and s.s_sex = '男'; -- 查询家庭地址为空的学生信息
select * from studentinfo s where s.s_address is null; -- 查询毕业学校不为空的学生信息
-- is null
-- is not null
select * from studentinfo s where s.s_school is not null;
select * from studentinfo s where not s.s_school is null; -- 查询年龄大于24的本科生信息
select * from studentinfo s where s.s_age > 24 and s.s_xueli = '本科'; -- 查询年龄是19,24,26的学生信息
select *
from studentinfo s
where s.s_age = 19
or s.s_age = 24
or s.s_age = 26; select * from studentinfo s where s.s_age in (19, 24, 26); -- = any() 等于括号里的任何一个值
select * from studentinfo s where s.s_age = any(19, 24, 26); -- > any() 大于最小值
select * from studentinfo s where s.s_age > any(22, 24, 26); -- < any() 小于最大值
select * from studentinfo s where s.s_age < any(22, 24, 26); -- > all() 大于最大值
select * from studentinfo s where s.s_age > all(22, 24, 26); -- < all() 小于最小值
select * from studentinfo s where s.s_age > all(22, 24, 26); -- distinct 去除查询结果重复值
-- all 不去除查询结果重复值 -- 查询所有的学历
select distinct s.s_xueli from studentinfo s; select all s.s_xueli from studentinfo s; select distinct s.s_xueli, s.s_sex from studentinfo s; -- order by 排序
-- order by 列 [asc(默认方式)|desc] -- 查询所有学生的姓名和年龄,并按照年龄降序排序
select s.s_name, s.s_age from studentinfo s order by s.s_age desc; -- 模糊查询 -- % 匹配任意多个字符
-- _ 匹配一个字符 -- 查询以S字符开头的所有员工姓名
select e.ename from emp e where e.ename like 'S%'; -- 查询以S字符结尾的所有员工姓名
select e.ename from emp e where e.ename like '%S'; -- 查询包含S字符的所有员工姓名
select e.ename from emp e where e.ename like '%S%'; -- 查询名字包含5个字符的员工姓名
select e.ename from emp e where e.ename like '_____'; -- 查询名字以S字符开始且包含5个字符的员工姓名
select e.ename from emp e where e.ename like 'S____'; ------------- 子查询 --------------
--emp 员工信息表(employee)
-- empno 员工编号
-- ename 员工姓名
-- job 职位
-- mgr 主管员工编号(manager)
-- hiredate 入职日期
-- sal 工资(salary)
-- comm 提成
-- deptno 部门编号(department number) -- dept 部门信息表(department)
-- deptno 部门编号
-- dname 部门名字
-- loc 上班地点 (location) select * from emp e;
select * from dept d; --查询SMITH所在部门的名字 select d.dname
from dept d
where d.deptno = (select e.deptno from emp e where e.ename = 'SMITH'); -- 查询SMITH的主管名字 select a.ename
from emp a
where a.empno = (select b.mgr from emp b where b.ename = 'SMITH'); select * from emp e;
-- 查询工资高于1600的员工信息
select * from emp e where e.sal > 1600; -- 查询工资高于ALLEN的员工信息
select * from emp e where e.sal > (select sal from emp where ename='ALLEN') ; -- 查询工资高于30号部门所有人的员工信息 select *
from emp e
where sal > all(select sal from emp where deptno = 30); -- 查询销售部(SALES)的员工姓名 select e.ename
from emp e
where e.deptno = (select d.deptno from dept d where d.dname = 'SALES'); -- 查询销售部的工资高于1300的员工姓名
select e.ename
from emp e
where e.sal > 1300
and e.deptno = (select d.deptno from dept d where d.dname = 'SALES'); -- 伪列 rowid,rownum
-- rowid 行id,标示该行的物理存储位置
-- rownum 行编号
select rowid,rownum,e.* from emp e; -- 分页查询 -- 查询员工表前三行
select * from emp e where rownum <= 3; --查询员工表第三行到第五行
select a.*
from (select rownum r, e.* from emp e) a
where r >= 3
and r <= 5; -- 查询工资最高的三个员工信息 -- 先筛选数据,再对选出的数据(行)排序
--select * from emp e where rownum <= 3 order by e.sal desc;
select * from (select * from emp order by sal desc) e where rownum <= 3; --按照工资降序排序,查询员工表第三行到第五行
select a.*
from (select rownum r, e.* from (select * from emp order by sal desc) e) a
where r >= 3
and r <= 5;

oracle 常用语句2的更多相关文章

  1. ORACLE常用语句:

    ORACLE常用语句: 1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新 ...

  2. Oracle常用语句集合

    oracle常用经典SQL查询 常用SQL查询: .查看表空间的名称及大小 )),) ts_size from dba_tablespaces t, dba_data_files d where t. ...

  3. Oracle常用语句

    Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...

  4. Oracle常用语句语法汇总

    第一篇  基本操作 --解锁用户   alter user 用户 account unlock; --锁定用户   alter user 用户 account lock; alter user sco ...

  5. oracle常用语句总结

    一.用户管理类 1.创建用户: Create user username Identified by password Default tablespace tablespacename Tempor ...

  6. oracle 常用语句

    创建用户及授权create temporary tablespace test_temp tempfile 'C:\oracle\product\10.2.0\oradata\hszxdbtemp.d ...

  7. oracle 常用语句3

    - oracle 函数 select sign(-3),sign(3), sign(0) from dual; select ceil(3.7) from dual; select floor(3.7 ...

  8. Oracle 常用语句1

    -- 我是注释信息 sql语句 -- 创建用户: create user 用户名 identified by 密码; create user jack identified by j123; -- l ...

  9. 查锁住的表,以及kill进程,Oracle常用语句

    --找出所有被锁的对象,定位出哪个回话占用 select l.session_id,o.owner,o.object_name from v$locked_object l,dba_objects o ...

  10. Oracle 常用语句备份

    1.oracle 11g 用户名和密码默认区分大小写,可更改alter system set sec_case_sensitive_logon=false 设置改为不区分大小写. 2.授权创建视图:G ...

随机推荐

  1. 学习Validator验证框架总结

    在项目开发中许多地方需要加以验证,对于使用if-else简单粗暴一个一个验证,spring的validation封装了Javax ValidationI校验参数,大大缩减了代码量. 以前的分层验证,从 ...

  2. 给力啊!这篇Spring Bean的依赖注入方式笔记总结真的到位,没见过写的这么细的

    1. Bean的依赖注入概念 依赖注入(Dependency Injection):它是 Spring 框架核心 IOC 的具体实现.在编写程序时,通过控制反转,把对象的创建交给了 Spring,但是 ...

  3. Codeforces1009F Dominant Indices

    dsu on tree 题目链接 点我跳转 题目大意 给定一棵以 \(1\) 为根,\(n\) 个节点的树.设\(d(u,x)\) 为 \(u\) 子树中到 \(u\) 距离为 \(x\) 的节点数. ...

  4. 第四章:动态规划I

    4.1背包问题 动态规划的核心:如何构造一个高效的备忘录,提高整个问题求解的效率. 4.2最大子数组问题II

  5. 编程入门选什么语言好?C 语言还是Python ?为你解析

    前面我分享过计算机行业已经成了学校选择排名第一,家长和学生都很看好计算机类专业.现在IT行业也越来越火爆,程序员越来越被人看好.面对相比同龄人高薪资的诱惑,人们很难不心动,即使秃头也值得! 那么问题来 ...

  6. High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis

    论文来源:CVPR 2017 摘要 之前方法的缺点:之前的方法是基于语义和上下文信息的,在填充较大holes的表现得很好,能够捕获更高级的图像特征,但是由于内存限制和难以训练网络的因素,只能处理分辨率 ...

  7. C++调用C接口

    目录 C++调用C代码 解决调用失败问题 思考:那C代码能够被C程序调用吗 C代码既能被C++调用又能被C调用 C++调用C代码 一个C语言文件p.c #include <stdio.h> ...

  8. 真香!Python开发工程师都选择这个数据库:因为它免费

    数据库类别 既然我们要使用关系数据库,就必须选择一个关系数据库. 目前广泛使用的关系数据库也就这么几种: 付费的商用数据库: Oracle,典型的高富帅: SQL Server,微软自家产品,Wind ...

  9. charles功能(四) 模拟 接口404/403返回值(blacklist方法)

    1.tools-->blacklist 2.允许启用黑名单选择接口返回错误的形式 (404或者403),添加接口地址并保存 3.再次请求效果如下

  10. mysql索引原理以及优化

    一.常见查找算法: 1.顺序查找: 最基础的查找方法,对比每一个元素进行查找.在数据量很大的时候效率相当的慢. 数据结构:有序或者无需的队列 时间复杂度:O(n) 2.二分查找: 二分查找首先要求数组 ...