码迷,mamicode.com
首页 > 数据库 > 详细

SQL2

时间:2017-07-13 20:43:19      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:--   nullif   images   mon   abc   lower   har   ber   选择   

一,过滤和排序数据
       使用WHERE 子句,将不满足条件的行过滤掉。

        SELECT    *|{[DISTINCT] column|expression [alias],...}
         FROM    table
         [WHERE    condition(s)];
        WHERE 子句紧随 FROM 子句
     

      字符和日期要包含在单引号中。
      字符大小写敏感,日期格式敏感。
      默认的日期格式是 DD-MON-RR

      使用 LIKE 运算选择类似的值
      选择条件可以包含字符或数字:
      % 代表零个或多个字符。
       _ 代表一个字符。比较运算符
技术分享

 

技术分享

逻辑操作符符

 技术分享

单行函数:
        操作数据对象
        接收函数返回一个结果
        只对一行进行操作
        每行返回一个结果
        可以转换数据类型
        可以嵌套
        参数可以是一列或一个值
       例如:

select upper (‘abcde‘)from dual;--转换大写
select *from emp where ename =upper (‘smith‘);
select lower (‘ABCDE‘)from dual;--转换小写
select initcap(ename)from emp;--首字母大写
select concat(‘hello‘,‘word‘)from dual;
select round (156.326,2)from dual; --四舍五入
select trunc (566.526,2)from dual;--截断
select mod (1700,200)from dual;--求余
select months_between(sysdate,hiredate)from emp;--两个日期之间相差的月数
select add_months (sysdate,1)from dual;--指定日期加上几个月
select next_day(sysdate,‘星期一‘)from dual;--指定日期的下一个日期
select last_day(sysdate)from dual;--月份的最后一天
select round(sysdate,‘month‘)from dual;
select round(sysdate,‘year‘)from dual;
select trunc(sysdate,‘month‘)from dual;
select trunc(sysdate,‘year‘)from dual;
select to_char(sysdate,‘yyyy‘)from dual;
select to_char(sysdate,‘yyyy-mm-dd‘)from dual;
select to_char(sal,‘l999,999,999‘)from emp;
select to_char(sysdate,‘D‘)from dual;
select to_number(‘13‘)+to_number(‘18‘)from dual;--字符转数字
select sysdate from dual;
select to_date(‘20170713‘,‘yyyymmdd‘)from dual;
select nvl(comm,0)from emp;
select nullif(comm,0)from emp;
select empno,ename,sal,comm,nvl2(comm,sal+comm,sal)total from emp;
select empno,ename,sal,comm,coalesce(sal+comm,sal,0)from emp;


select empno,lpad(initcap(trim(ename)),10,‘‘)name,job,sal from emp;--单行嵌套
select ename,empno,sal from emp where sal=1250;
select empno,ename,sal from emp where ename=‘WARD‘;
select ename,sal from emp where sal between 2500 and 3500;
select ename,sal, empno from emp where sal in(800,1500,3000);
select ename,sal,empno from emp where sal not in(800,1500,3000);
select ename,sal,empno from emp where sal>=1500 or empno>7700;
select deptno,sal,empno from emp where (sal>=2000 or empno>7800) and deptno>10;
select deptno,sal,ename from emp order by sal desc;
select deptno,sal,ename from emp order by ename;

 

SQL2

标签:--   nullif   images   mon   abc   lower   har   ber   选择   

原文地址:http://www.cnblogs.com/ypc120336/p/7162222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!