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 ...
随机推荐
- PAT 1025. 反转链表 (25)
给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转.例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4:如果K为4,则输出应该为4→3→2→1→5→6,即最后 ...
- Pycharm: keyboard reference
Source: Official set ♥ Editing Ctrl + Space Basic code completion (the name of any class, method or ...
- mysql中判断记录是否存在方法比较
我这里总结了判断记录是否存在的常用方法: sql语句:select count(*) from tablename; 然后读取count(*)的值判断记录是否存在.对于这种方法性能上有些浪费,我们只是 ...
- zabbix常用术语
zabbix常用术语
- C语言 自动修改文件名小程序
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...
- VMware Fusion DHCP方式下如何指定虚拟机IP地址
默认情况下,vmware fusion中的虚拟机,网卡设置成dhcp(动态分配 )时,会分配一个IP地址,但这个IP通常很难记,如果我们想为某台虚拟机挑一个好记的IP地址,可以按如下步骤操作: 命令行 ...
- jboss EAP 6.2 + Message Drive Bean(MDB) 整合IBM Webshpere MQ 7.5
上一篇我们知道了消息驱动Bean的基本用法,实际大型分布式企业应用中,往往会采用高性能的商业Queue产品,比如IBM Webshpere MQ(目前最新版本是7.5 ),下面讲解下如何在Jboss ...
- Qt学习笔记 TableWidget使用说明和增删改操作的实现
看一下效果很简单的一个小功能 先说分部讲一下过程 再给出详细代码 添加数据 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ...
- lecture10-模型的结合与全贝叶斯学习
这是Hinton的第10课 这节课有两篇论文可以作为背景或者课外读物<Adaptive mixtures of local experts>和<Improving neural ne ...
- Log4net使用(一)
LogHelper.cs using NLog; using NLog.Targets; namespace MyProject.Tool.Log { public class LogHelper { ...