-- 在sql中只有别名时用的是双引号
select employee_id,last_name,12*salary as yearSalary from employees;

select last_name from employees;

select department_id from department;

select last_name,department_id from employees;

select last_name from employees;

select employee_id,last_name,department_id from employees;

select employee_id,last_name,department_id from employees where employee_id > 200 ;

-- 日期和字符串是放在的单引号中的在字符串中区分大小写的
select employee_id,last_name from employees where last_name = 'Chen' ;

select employee_id,last_name from employees where hire_date = '7-6月-1994' ;

select last_name from employees where to_char(hire_date,'yyyy-mm-dd') = '1994-06-07' and salary >4000;

select last_name ,salary from employees where

select last_name from employees where salary between  4000 and 7000;

select last_name,salary from employees where salary in (4000 , 7000);
select last_name from employees where last_name like 's' ;

select last_name,commission_pct from employees where commission_pct no is null ;

-- 单行函数

select count(employee_id) from employees;

select lower('ATGUIFU'),UPPER('atguigu'),initcap('Atguigu java') from dual;

select last_name from employees where lower(last_name) = 'king';

select substr('hello world',0,5) from dual

select instr('hello java','L') from dual;

select employee_id last_name lpad(salary,10,' ') from employees;

select trim('h' from 'hsdfsfsfasdh') lpad(salary,10,' ') from employees;

select replace('abcsdbb','b','X') from dual;

-- 数字函数

select round(435.45,2),round(435.45),round(435.45,-2) from dual;

select trunc(435.45,2),trunc(435.45),trunc(435.45,-2) from dual;

select sysdate,sysdate+1 ,sysdate-3,from dual;

select employee_id ,last_name, sysdate-hire_date as workDays from employees;

select add_months(sysdate,2),add_months(sysdate,-3),next_day(sysdate,'星期日') from dual:

select employee_id ,last_name, hire_date from employees where hire_date=last_day-1;

select employee_id, hire_date from employees where hire_date  = to_char(hire_date,'yyyy-mm-dd') = '1997-06-07';

select employee_id, hire_date from employees where to_date('1997-06-25','yyyy-mm-dd') = hire_date;

-- number to char

select to_char(122323444.89,'999,999,9999,.99') from dual;

-- 前缀加当地的货币符号
select to_char(122323444.89,'L999,999,9999,.99') from dual;
-- 前缀加$符号
select to_char(122323444.89,'$999,999,9999,.99') from dual;
-- 用0填充
select to_char(122323444.89,'000,999,9999,.99') from dual;

select to_number('$001,234,234.89','$000,000,999.99') from dual;

-- 求员工的年薪
select employee_id,last_name,salary*12*(1+commission_pct) from employees;

select employee_id,last_name,nvl(department_id,'没有部门') from employees;

select last_name,commission_pct ,nvl(commission_pct+0.015,commission_pct+0.01) as tt from employees;

select last_name,department_id,case department_id
when 10 then salary *1.1
when 20 then salary *1.2
when 30 then salary *1.3
else salary
end  as ss
from employees;

select last_name,department_id,decode(department_id,10 ,salary *1.1
,20 ,salary *1.2
,30 ,salary *1.3
,salary
)   as ss
from employees;

select TO_CHAR(sysdate,'yyyy"年"MM"月"dd"日" HH:mm:ss') from dual;

-- 多表查询

SQL> select employee_id,departments.department_id ,department_name from employee
s ,departments;

select employee_id,departments.department_id ,departments.department_name
 from employees ,departments where departments.department_id = employees.department_id;

select q.employee_id,w.department_id ,w.department_name
 from employees as q,departments as w
 where w.department_id = q.department_id;

select e.last_name,e.department_id,d.department_name from employees e, departments d  where e.department_id = d.department_id;

-- 左外连接
select e.last_name,e.department_id,d.department_name from employees e, departments d  where e.department_id = d.department_id(+);
-- 内连接,等值&不等值的
--外连接 左外连接,又外连接
select e.last_name,e.department_id,d.department_name from employees e, departments d  where e.department_id(+) = d.department_id;

select e.last_name,e.department_id,d.department_name,city from employees e left join departments d  on e.department_id = d.department_id ;

-- 全连接
select e.last_name,e.department_id,d.department_name from employees e  full
  join departments d  on e.department_id = d.department_id ;

-- 自连接
select e1.employee_id,e1.last_name,e1.manager_id from employees e join employees e1 on e.manager_id = e.employee_id where e.last_name = 'Chen';
-- 分组函数

select salary from employees group by salary;

select max(salary)from employees group by salary;

select min(salary),avg(salary),count(1),sum(salary)  from employees ;
 
 -- count 计算的是不为空的值
 select count(commission_pct) from employees;
  select  commission_pct  from employees WHERE commission_pct is  ;
 
 select avg (nvl(commission_pct,0)) from employees;
 
 select avg(salary) from employees group by department_id;
 
 select distinct department_id from employees;
 
 -- group by 后面的字段之间用逗号连接
 select department_id ,job_id,avg(salary) from  employees group by department_id,job_id;
 
  select avg(salary) from employees group by department_id;
 
 
  select department_id ,job_id,avg(salary) from  employees group by department_id;

oracle 常用sql的更多相关文章

  1. oracle常用SQL语句(汇总版)

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

  2. oracle 常用sql语句

    oracle 常用sql语句 1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom d ...

  3. Oracle常用SQL查询(2)

    三.查看数据库的SQL 1 .查看表空间的名称及大小 select  t.tablespace_name,  round ( sum (bytes / ( 1024 * 1024 )), 0 ) ts ...

  4. Oracle常用SQL查询

    一.ORACLE的启动和关闭 1.在单机环境下要想启动或关闭oracle系统必须首先切换到oracle用户,如下: su - oracle a.启动Oracle系统 oracle>svrmgrl ...

  5. ORACLE 常用SQL查询

    一.ORACLE的启动和关闭 1 .在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su  -  oracle a.启动ORACLE系统 oracle > sv ...

  6. Oracle常用SQL语句大全

    常用Oracle数据库SQL语句汇总. 1.常用操作 --清空回收站purge recyclebin;--查询回收站select * from recyclebin--查询Oracle版本信息sele ...

  7. Oracle常用sql命令

    1.查看数据库归档是开启还是关闭SQL> archive log list 更改数据库归档模式: SQL> shutdown immediateSQL> startup mountS ...

  8. oracle 常用sql字符函数介绍

    常用字符函数介绍 1.ascii 返回与指定的字符对应的十进制数: SQL>select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') ...

  9. Oracle 常用Sql 语句

    Oracle数据库常常被用作项目开发的数据库之一:有时隔段时间没使用就会忘记一些常用的sql语法,所以我们有必要记录下常用的sql 语句,当我们需要时可以快速找到并运用. 1 创建表空间.创建用户及授 ...

  10. Oracle常用sql语句(一)

    # Sql的分类 # DDL (Data Definition Language):数据定义语言,用来定义数据库对象:库.表.列等: CREATE. ALTER.DROP DML(Data Manip ...

随机推荐

  1. myeclipse 8.5离线安装python插件

    看到网上很多教程扯了一大堆,好麻烦的样子. 1)下载pyhon开发插件,PyDev 2.2.0.zip 我在百度137708820网盘里已分享,链接http://pan.baidu.com/s/1mg ...

  2. githup上传代码

    把自己本地东西上传到GitHup上. 本文内容来自于http://blog.csdn.net/yuanzichao/article/details/44922593 1.安装msysgit和Torto ...

  3. 005商城项目:ssm框架的整合成功之后的问题:使用maven的tomcat插件时的debug

    在执行maven的clean时经常碰到一个问题: 解决: 然后: 还有一个问题是:用maven 使用Debug调试时,不能看到源代码. 解决办法: 下面选择Debug Configurations 这 ...

  4. rpc框架: thrift/avro/protobuf 之maven插件生成java类

    thrift.avro.probobuf 这几个rpc框架的基本思想都差不多,先定义IDL文件,然后由各自的编译器(或maven插件)生成目标语言的源代码,但是,根据idl生成源代码这件事,如果每次都 ...

  5. 《程序设计教学法--以Java程序设计为例》

    <程序设计教学法--以Java程序设计为例> 当老师上的第一门课就是<Java程序设计>,工作以来,断断续续上了近十次课了吧.十几年来,教材.课程内容.教学方法.教学手段不断改 ...

  6. java 实现从15位~18位的身份证号码转换,校验中国大陆公民身份证、香港居民身份证、澳门身份证和台湾身份证。

    package xidian.sl.netcredit.util; /** * Copyright (C) 2009-2010 Yichuan, Fuchun All rights reserved. ...

  7. 如何在 ie6 中使用 "localStorage"

    好吧,我只是个标题党,ie6 下根本无法使用跟 h5 沾边的 localStorage.今天要向大家介绍的是 ie 特有的 userData 的存储方式,并且对它进行封装,使得不支持 localSto ...

  8. 迭代和递归 - leetcode 206. Reverse Linked List

    Reverse Linked List,一道有趣的题目.给你一个链表,输出反向链表.因为我用的是JavaScript提交,所以链表的每个节点都是一个对象.例如1->2->3,就要得到3-& ...

  9. hystrix-turbine 监控的使用

    1.   概述 Demo地址:http://git.oschina.net/zhou666/spring-cloud-7simple/tree/master/cloud-hystrix-turbine ...

  10. android之MP3播放器(1)

    该播放器只是对本地的MP3文件进行简单的播放 布局文件 布局文件中设置了三个按钮分别来进行播放.暂停和继续播放 <?xml version="1.0" encoding=&q ...