oracle 常用sql
-- 在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的更多相关文章
- oracle常用SQL语句(汇总版)
Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...
- oracle 常用sql语句
oracle 常用sql语句 1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom d ...
- Oracle常用SQL查询(2)
三.查看数据库的SQL 1 .查看表空间的名称及大小 select t.tablespace_name, round ( sum (bytes / ( 1024 * 1024 )), 0 ) ts ...
- Oracle常用SQL查询
一.ORACLE的启动和关闭 1.在单机环境下要想启动或关闭oracle系统必须首先切换到oracle用户,如下: su - oracle a.启动Oracle系统 oracle>svrmgrl ...
- ORACLE 常用SQL查询
一.ORACLE的启动和关闭 1 .在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle > sv ...
- Oracle常用SQL语句大全
常用Oracle数据库SQL语句汇总. 1.常用操作 --清空回收站purge recyclebin;--查询回收站select * from recyclebin--查询Oracle版本信息sele ...
- Oracle常用sql命令
1.查看数据库归档是开启还是关闭SQL> archive log list 更改数据库归档模式: SQL> shutdown immediateSQL> startup mountS ...
- oracle 常用sql字符函数介绍
常用字符函数介绍 1.ascii 返回与指定的字符对应的十进制数: SQL>select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') ...
- Oracle 常用Sql 语句
Oracle数据库常常被用作项目开发的数据库之一:有时隔段时间没使用就会忘记一些常用的sql语法,所以我们有必要记录下常用的sql 语句,当我们需要时可以快速找到并运用. 1 创建表空间.创建用户及授 ...
- Oracle常用sql语句(一)
# Sql的分类 # DDL (Data Definition Language):数据定义语言,用来定义数据库对象:库.表.列等: CREATE. ALTER.DROP DML(Data Manip ...
随机推荐
- Asp.net NVelocity 模版引擎
NVelocity.dll是Java中常用的一个模版,下面是常用的模版引擎 1,返回string类型的html代码 /// <summary> /// 获取html模版 /// </ ...
- 升级nodejs版本
node有一个模块叫n,是专门用来管理node.js的版本的. 首先安装n模块: npm install -g n 第二步: 升级node.js到最新稳定版 n stable n后面也可以跟随版本号比 ...
- P3398 仓鼠找sugar
P3398 仓鼠找sugar 题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而 ...
- jquery常用代码
转自:未找到 以下是jquery中比较常用的一些操作实现方式: $("标签名") //取html元素 document.getElementsByTagName("&qu ...
- 2016shenyang-1002-HDU5893-List wants to travel-树链剖分+线段树维护不同区间段个数
肯定先无脑树链剖分,然后线段树维护一段区间不同个数,再维护一个左右端点的费用. 线段树更新,pushDown,pushUp的时候要注意考虑链接位置的费用是否相同 还有就是树链剖分操作的时候,维护上一个 ...
- unix环境高级编程基础知识之第一篇
陆陆续续看完了圣经第一章,熟悉了unix的整个编程流程,c语言的用处在这里得到伸张. 从unix的体系结构,原来操作系统包括内核及一些其他软件,我们常常误称为linux内核为操作系统,这俨然成为一种共 ...
- http缓存提高性能
秋招也算是正式结束了,现在整理一下笔记,当作巩固一下知识,也希望这个对大家有帮助 http 缓存 和 cdn 缓存可以说是面试必问的问题,竟然是必问的问题,那就总结全面一点- http缓存机制 缓存分 ...
- 《深入理解Spark:核心思想与源码分析》(前言及第1章)
自己牺牲了7个月的周末和下班空闲时间,通过研究Spark源码和原理,总结整理的<深入理解Spark:核心思想与源码分析>一书现在已经正式出版上市,目前亚马逊.京东.当当.天猫等网站均有销售 ...
- JavaScript 10分钟入门
JavaScript 10分钟入门 随着公司内部技术分享(JS进阶)投票的失利,先译一篇不错的JS入门博文,方便不太了解JS的童鞋快速学习和掌握这门神奇的语言. 以下为译文,原文地址:http://w ...
- linux开机自动启动
1 .vi /etc/rc.local 2.编写开机后运行的命令 如:service httpd start