-- 在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. Centos5.8 安装 PHP5.5 和 memcached

    安装GIT 需要先安装gcc-c++ (sudo yum install gcc-c++) sudo yum install gettext-devel expat-devel cpio perl o ...

  2. TP框架中用tp模版迁移smarty模版的注意事项

    ThinkPHP使用Smarty模板引擎的流程及注意事项在多人合作的项目中,Smarty模板使用的最多,具体原因百度. 而ThinkPHP中默认使用的模板是Think自己的模板,这就需要修改默认的模板 ...

  3. typeof关键字简介 -rtti

    typeof关键字是C语言中的一个新扩展.只要可以接受typedef名称,Sun Studio C 编译器就可以接受带有typeof的结构,包括以下语法类别: 声明 函数声明符中的参数类型链表和返回类 ...

  4. Linux system函数详解

    system 功能:system()函数调用"/bin/sh -c command"执行特定的命令,阻塞当前进程直到command命令执行完毕 原型 int system(cons ...

  5. SQL Server存储过程中使用表值作为输入参数示例

    这篇文章主要介绍了SQL Server存储过程中使用表值作为输入参数示例,使用表值参数,可以不必创建临时表或许多参数,即可向 Transact-SQL 语句或例程(如存储过程或函数)发送多行数据,这样 ...

  6. 机械大楼电梯控制项目软件 -- github团队组建

    目前在Github网站上建立了机械大楼电梯控制项目软件的软件仓库(Repository),提供了软件功能需求说明文档和Automation Studio程序模板.地址为 https://github. ...

  7. 虚拟机开机提示Operating System not found解决办法

    为了更好体验windows更多操作系统,有些用户会在VMware虚拟机中安装XP.win7或win8等等系统,有用户反映在虚拟机中安装XP开机后提示"Operating System not ...

  8. nodejs学习之实现http数据转发

    此前在做项目的时候,一直用json文件用作模拟数据,后来发现了mock.js,于是就用了mock.js,再后来感觉这些数据再怎么模拟都是静态数据.所以就想用nodejs实现一个数据转发功能,在本地拉取 ...

  9. 构造函数的return返回值

    3 1. 2. 3.

  10. SQL Server使用游标或临时表遍历数据

    方法一:使用游标(此方法适用所有情况,对标结构没有特殊要求.) declare @ProductName nvarchar() declare pcurr cursor for select Prod ...