Oracle的函数及基本语法

Oracle

3.3、简单的 Select 语句

3.4、使用算术表达式 + - / *

3.5、连接运算符 || (相当于拼接)

3.6、使用字段别名 as

3.7、空值 is null

3.8、去除重复行 distinct

3.9、查询结果排序 order by asc(desc)

3.10、比较运算符 > < (!= or <>) between and

3.11、in 操作 not in 3.12、模糊查询 like

3.12 nvl(comm,0) 把comm null空的字段替换成0

3.13 Length Select length(ename) from emp;

3.14 Trim trim(’ Mr Smith ') 过滤首尾空格 trim()Mr Smith

3.15 CASE 表达式

select empno, ename, sal,

case deptno when 10 then ‘财务部’ when 20 then ‘研发部’ when 30 then ‘销售部’ else ‘未知部门’

end 部门 from emp;

3.16 DECODE()函数 和 case 表达式类似,decode()函数也用于实现多路分支结构

select empno, ename, sal, decode(deptno, 10, ‘财务部’, 20, ‘研发部’, 30, ‘销售部’, ‘未知部门’) 部门 from emp

3.17、日期函数

Months_between() select months_between(sysdate,hiredate) from emp;

Add_months() select add_months(sysdate,1) from dual;

Next_day() select next_day(sysdate,‘星期一’) from dual; Last_day select last_day(sysdate) from dual;

案例

-- 用户连接
--conn system/123456;
-- 创建表空间,对表空间进行
--create tablespace shuhao datafile 'd:/Oracle/tablespace/shuhao.ora1' siae 10m,'d:/Oracle/tablespace/shuhao1.ora1'size 5m autoextend on;
--创建用户
--create user yang identified by 123456 default tablespace shuhao temporary tablespace temp;
-- 删除表空间
--drop tablespace shuhao including contents and datafiles cascade constant;
-- 给用户授权
--grant create session to yang;
--grant resource to yang;
-- 创建表
--create tablespace shu(id integer);

-- 给一个用户表的权限赋予另一个用户insert及update权限,也可以写成all
--grant all on yang.shu to scott;

-- conn scott/123456;
--1.查询每个员工的年薪
--select sal*12 nx from emp ;
-- 2.查询出员工名ename与工作岗位job,以:进行拼接
-- select ename || ':' || job from emp;
-- 3.查询出有奖金的人员
-- select * from emp where  comm is null;
-- 4.查询公司提供了那些岗位
-- select distinct job from emp ;
-- 5.查询出公司的工资,从高到低进行排列
--select * from emp   order by SAL desc;
-- 6.查询工资在1000-2000之间
--select * from emp where sal>=1000 and sal<=2000;
-- select * from emp where sal between 1000 and 2000;
-- 7.in 或者是not in 编号是10 20 30
--select * from emp where deptno in(10,20);
--select * from emp where deptno=10 or deptno=20; 
-- select * from emp where deptno<=20;
--8查询员工以M开头的
--- select * from emp where ename like 'M%';
-- 查询员工姓名以C开头,并且是5个字符的
--select * from emp where ename like 'C____';

--select * from dept;
--select * from bonus;
-- select * from salgrade;
--select job from emp;
 --select round(412,-2) from dual;
--select round(412,-2) from dual;
-- select trunc(421.222,3) from dual;
-- select nvl(comm,0) from emp;-- 如果是null则用0来替换
--select now();
-- select sysdate from dual;
--select * from dept;
--select * from emp;
--select EMPNO,ENAME,JOB,MGR HIREDATE,SAL,COMM,
  --     case DEPTNO
 --      when 10 then '财务部'
  --     when 20 then '销售部'
   --    when 30 then '市场部'
   --     else '其他部门'
    --      end 部门 from emp;
  --select  EMPNO,ENAME,JOB,MGR HIREDATE,SAL,COMM,
   --decode(DEPTNO,10,'财务部',20,'市场部',30,'生产部') 部门 from emp; 
   
 -- 联合查询       
  -- select * from emp,dept;-- 会出现笛卡尔积
 -- select e.ename,d.loc from emp e,dept d where e.deptno=d.deptno and e.comm>0;
  --select d.*,e.* from emp e,dept d where e.deptno(+)=d.deptno;
 --select e.*,d.* from emp e  join dept d on d.deptno=e.deptno; 
   --select e.*,d.* from emp e  right outer join dept d on e.deptno=d.deptno; 
   -- 子查询 查询在 NEW YORK地点工作的员工信息
  --select * from dept;
  --select  * from emp where deptno=(select deptno from dept d where d.loc='NEW YORK');
   -- 查询在NEW YOR或者在 DALLAS工作员工信息
   select e.* from emp e,dept d where e.deptno=d.deptno and (d.loc='NEW YOR' or d.loc='DALLAS');









  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值