`

Oracle select 语句 案例大全

 
阅读更多

select * from emp;
select * from dept;
select * from salgrade;
select ename || sal from emp;
select distinct deptno from emp;
select distinct deptno, job from emp;
select * from emp where deptno = 10;
select * from emp where deptno <> 10;
select * from emp where sal between 500 and 1500;
select *
  from emp
 where sal >= 500
   and sal <= 1500;
select * from emp where comm is null;
select * from emp where comm is not null;
select * from emp where sal in (800, 1500, 2000);
select * from emp where ename in ('SMITH', 'TURNER', 'CHEN');
select * from emp where ename like '%ALL%';
select * from emp where ename like '%_A%';
select * from emp where ename like '%$%%' escape '$';
select * from emp order by empno asc;
select * from emp order by deptno asc, empno desc;
select substr(ename, 2, 3) from emp;
select ename, sal * 12 from emp;
select ename, sal * 12 annual_salary from emp;
select 2 * 3 from dual;
select sysdate from dual;
select chr(65) from dual;
select ascii('A') from dual;
select round(25.863) from dual;
select round(25.863, 1) from dual;
select round(25.863, -1) from dual;
select to_char(sal, '$99,999.9999') from emp;
select to_char(sal, 'L99,999.9999') from emp;
select to_char(sal, 'L0000.0000') from emp;
select to_char(hiredate, 'YYYY-MM-DD HH:MI:SS') from emp;
select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') from dual;
select *
  from emp
 where hiredate > to_date('1985-6-8 18:30:20', 'YYYY-MM-DD HH24:MI:SS');
select * from emp where sal > to_number('$1,500.00', '$9,999.99');
select ename, sal * 12 + nvl(comm, 0) from emp;
select round(avg(sal), 2) from emp;
select count(*) from emp where deptno = 10;
select count(comm) from emp;
select count(distinct deptno) from emp;
select deptno, avg(sal) from emp group by deptno;
select deptno, job, max(sal) from emp group by deptno, job;
select ename, sal from emp where sal = (select max(sal) from emp);
select deptno, max(sal) from emp group by deptno;
select avg(sal), deptno from emp group by deptno having avg(sal) > 2000;
select deptno, avg(sal)
  from emp
 where sal > 1200
 group by deptno
having avg(sal) > 1500
 order by avg(sal) desc;
select ename, sal from emp where sal > (select avg(sal) from emp);
select ename, sal
  from emp
  join (select max(sal) max_sal, deptno from emp group by deptno) t
    on (emp.sal = t.max_sal and emp.deptno = t.deptno);
select e1.ename, e2.ename from emp e1, emp e2 where e1.mgr = e2.empno;
select ename, dname from emp, dept where emp.deptno = dept.deptno;
select ename, dname from emp join dept on (emp.deptno = dept.deptno);
select ename, dname from emp join dept using (deptno);
--
select ename, grade
  from emp e
  join salgrade s
    on (e.sal between s.losal and s.hisal);
--
select ename, dname, grade
  from emp e
  join dept d
    on (e.deptno = d.deptno)
  join salgrade s
    on (e.sal between s.losal and s.hisal)
 where e.ename not like '_A%';
--
select e1.ename, e2.ename
  from emp e1
  left join emp e2
    on e1.mgr = e2.empno;
--
select e.ename, d.dname
  from emp e
 right join dept d
    on e.deptno = d.deptno;
--
select e.ename, d.dname from emp e full join dept d on e.deptno = d.deptno;
--
select deptno, avg_sal, grade
  from (select deptno, avg(sal) avg_sal from emp group by deptno) t
  join salgrade s
    on (t.avg_sal between s.losal and s.hisal);
--
select deptno, avg(grade)
  from (select deptno, grade
          from emp
          join salgrade s
            on (emp.sal between s.losal and s.hisal))
 group by deptno;
--
select ename from emp where empno in (select mgr from emp);
select ename from emp where empno in (select distinct mgr from emp);
--
select distinct sal
  from emp
 where sal not in
       (select distinct e1.sal from emp e1 join emp e2 on e1.sal < e2.sal);
--
select deptno, avg_sal
  from (select avg(sal) avg_sal, deptno from emp group by deptno)
 where avg_sal =
       (select max(avg_sal)
          from (select avg(sal) avg_sal from emp group by deptno));
--
select dname
  from dept
 where deptno =
       (select deptno
          from (select avg(sal) avg_sal, deptno from emp group by deptno)
         where avg_sal =
               (select max(avg_sal)
                  from (select avg(sal) avg_sal from emp group by deptno)));
--
select deptno, avg_sal
  from (select avg(sal) avg_sal, deptno from emp group by deptno)
 where avg_sal = (select max(avg(sal)) from emp group by deptno);

--grant create table,create view to scott;

create view v$_dept_avg_sal as
  select deptno, grade, avg_sal
    from (select avg(sal) avg_sal, deptno from scott.emp group by deptno) t
    join scott.salgrade s
      on (t.avg_sal between s.losal and s.hisal);

select dname, t.deptno, t.grade, t.avg_sal
  from v$_dept_avg_sal t
  join scott.dept
    on t.deptno = dept.deptno
 where t.grade = (select min(grade) from v$_dept_avg_sal);
--处理空值
select ename
  from emp
 where empno in (select distinct mgr from emp where mgr is not null)
   and sal >
       (select max(sal)
          from emp
         where empno not in
               (select distinct mgr from emp where mgr is not null));
--

insert into dept values (50, 'game', 'beijing');
select * from dept;
rollback;
select * from dept;
create table emp2 as
  select * from emp;
select * from emp2;
create table dept2 as
  select * from dept;
select * from dept2;
insert into dept2 (deptno, dname) values (60, 'game2');
select * from dept2;
insert into dept2
  select * from dept;
select * from dept2;
select * from emp2 where rownum <= 5;
select rownum r, ename from emp2;
select r, ename from (select rownum r, ename from emp2) where r > 10;
select ename, sal
  from (select ename, sal from emp2 order by sal desc)
 where rownum <= 5;
select ename, sal, r
  from (select ename, sal, rownum r
          from (select ename, sal from emp order by sal desc))
 where r >= 6
   and r <= 10;

update emp2 set sal=sal*2,ename=ename||'-' where deptno=10;
select sal,ename from emp2 where deptno=10;
delete from dept2 where deptno<25;
rollback;

分享到:
评论

相关推荐

    Oracle课程设计案例精编

    2. **SQL语言基础**:掌握SQL(Structured Query Language),包括SELECT语句用于查询数据,INSERT、UPDATE和DELETE用于修改数据,以及CREATE、ALTER和DROP用于管理数据库对象。 3. **数据库对象创建**:了解如何...

    Oracle 课程设计案例精编

    2. **SQL语言**:学习标准的SQL(结构化查询语言)用于数据查询、插入、更新和删除,包括SELECT语句的复杂查询,如联接、子查询、聚合函数和分组。 3. **PL/SQL编程**:Oracle特有的过程化语言,用于编写存储过程、...

    ORACLE课程设计案例精编

    2. SQL语言:Oracle支持标准SQL语法,包括SELECT、INSERT、UPDATE、DELETE语句用于数据查询、插入、修改和删除。此外,还有PL/SQL,Oracle的嵌入式过程语言,用于编写存储过程、函数和触发器,实现更复杂的业务逻辑...

    《Oracle课程设计案例精编》 源代码 赵京

    1. SQL查询:掌握复杂的SELECT语句,包括JOIN、子查询、聚合函数等,以解决实际数据查询问题。 2. 数据库设计:了解如何根据业务需求设计合理的数据模型,包括表结构和关系。 3. 存储过程和函数:学习编写PL/SQL代码...

    shell连接oracle数据库执行SQL工具脚本-支持select+inset+update

    shell连接oracle数据库工具脚本:支持select/insert/update/delete 部署位置:/root/sysmonitor db:数据库文件夹 dbconfig.properties:数据库配置文件, dbConnectTest.sh:连接测试文件 dbExecurteSQL.sh:...

    oracle经典sql案例

    - SQL-SELECT:这部分涉及的是SQL语句中SELECT语句的使用,说明文档将介绍如何通过SELECT语句从数据库中检索数据。 描述知识点: - 经典案例题:文档包含一系列标准的SQL练习题,旨在帮助学习者通过实践来理解和...

    oracle case语句的介绍

    ### Oracle CASE 语句介绍及应用案例 #### 一、Oracle CASE 语句概述 在 Oracle 数据库中,CASE 语句是一种非常实用且灵活的条件判断表达式,它可以用于根据不同的条件返回不同的值。CASE 语句可以分为两种类型:...

    Oracle入门语句

    1. **SELECT语句**:这是最基础的查询语句,用于从表中检索数据。例如,`SELECT * FROM table_name;` 会返回表table_name中的所有列。若需选择特定列,可以指定列名,如 `SELECT column1, column2 FROM table_name;`...

    Oracle查询优化改写技巧与案例

    案例:`SELECT t1.* FROM table1 t1 WHERE t1.id IN (SELECT t2.id FROM table2 t2 WHERE t2.status = 'active')`,可改写为`SELECT t1.* FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id WHERE t2.status = ...

    Oracle常用语句-总结文档汇总

    "Oracle常用语句-总结文档汇总"提供了丰富的资源,涵盖了SQL语句的基础到进阶应用,包括列行转换、SQL性能优化等多个关键知识点。 首先,列行转换是数据处理中常见的需求,Oracle提供了多种方法来实现这一操作。...

    oracle资料 包含经典案例 基础教程 和Oracleoracle_database_10g_为_dba_提供的最佳前_20_位的特性.pdf

    了解SQL的基本语法,如SELECT语句、JOIN操作、子查询以及事务处理,是成为Oracle开发人员的基础。此外,理解Oracle的数据模型,包括实体、关系、属性和键,有助于设计高效且可靠的数据库结构。 数据库架构方面,...

    ORACLE SQL 语句(典型应用总结).pdf

    根据提供的文档信息,本文将对...以上总结了Oracle SQL语句的一些典型应用案例,涵盖了基本的SELECT语句、限定与排序操作以及常用的功能函数,希望这些知识点能够帮助读者更好地理解和掌握Oracle SQL的相关知识。

    oracle学习案例

    "Oracle学习案例"是一个针对初学者和软件开发人员设计的实践教程,旨在帮助他们理解和掌握Oracle数据库的基础及进阶知识。 Oracle数据库的核心概念包括: 1. **数据模型**:Oracle遵循关系型数据模型,其中数据被...

    oracle游标案例

    以下是对"oracle游标案例"的详细解释。 1. **游标概念**: 游标(Cursor)在Oracle中是一个数据库对象,用于存储查询结果集的指针,它能够移动到结果集的不同行上,使得我们能够逐行读取、修改或处理数据。游标...

    Oracle数据案例 C语言源码 C语言Oracle案例

    标题中的“Oracle数据案例 C语言源码 C语言Oracle案例”表明这是一个关于使用C语言与Oracle数据库进行交互的实践教程或代码示例集。这个压缩包可能包含了一系列的C语言源代码文件,这些文件展示了如何通过编程接口...

    120套Oracle经典案例库(命令表).pdf

    - **子查询**:在`SELECT`语句中嵌套另一个`SELECT`语句。 - **连接查询**:使用`JOIN`操作符连接两个或多个表,以获得所需数据。 - **分组查询**:使用`GROUP BY`和聚合函数(如`COUNT`, `AVG`, `MAX`, `MIN`等)来...

    一个使用myeclipse 和oracle 结合使用的案例

    【标题】: "MyEclipse与Oracle结合使用案例解析" 【描述】: 本文将深入探讨如何在MyEclipse集成开发环境中与Oracle数据库进行有效整合,实现数据对象的操作。我们将重点讲解不同方式的连接策略以及具体操作步骤,...

    Oracle 课程设计案例精编.rar

    2. **SQL语言**:Oracle支持标准的SQL语句,如SELECT、INSERT、UPDATE、DELETE等,同时还有Oracle特有的SQL扩展,如PL/SQL块、游标、子查询等。 3. **表和索引**:创建、修改和删除表的语法,理解不同类型的索引(B...

Global site tag (gtag.js) - Google Analytics