Oracle笔记2

06:where语句:select * from emp where deptno = 10;

                            select * from emp where ename = 'clark';

                            select ename,sal from emp where sal > 1500;

                            select ename,sal,deptno from emp where deptno <> 10;//<>:不等于

                            select ename,sal from emp where ename > 'CBA';//比较ascii码大小;

                            select ename,sal from emp where sal between 800 and 1500;

     空值处理:select ename,sal,comm from emp where comm is (not) null;

     in语句:select ename,sal,comm from emp where sal in <800,1500,2000>

                      select ename,sal,comm from emp where ename in ('SMITH','KING','ABC')

     日期处理:select ename,sal,hiredate from emp where hiredate > '20-2月-81';

     过滤条件连接:where deptno = 10 and sal > 10;where deptno = 10 or sal > 10;where not in (800,1500);

     模糊查询:where ename like '%ALL%';

                          where ename like '_A%';//%代表一个或多个字符,下划线代表一个;

                          where ename like '%\%%';//'\'是转义字符

                          where ename like '%$%%' escape '$';//表明¥是转移字符

07:数据的排序order by:直接select,按插入顺序显示。

                            select * from dept order by deptno desc;//desc:descent,降序排列

                            select empno,ename from emp order by empno asc;//asc:ascent,升序(默认)

                            select empno,ename from emp where deptno <> 10 order by deptno asc;//先过滤后排序

                            select ename,sal,deptno from emp order by deptno asc,ename desc;//先按deptno升序。后按ename降序

08:常见的sql语句:lower语句:select lower(ename) from emp;select ename from emp where lower(ename) like '_a%';

                                    uper语句;

                                    substring:select substr(ename,2,3) from emp;

                                    char(把一个数字转换成一个字符):select chr<65> from dual;

                                    ascii:select ascii<'A'> from dual;

                                    round:select round<23.652,2> from dual;//四舍五入;

                                    to_char:select to_char from emp;//重点,必须记住!

                                    注:L代表本地符号;若9改为0,前面加0;

                                    select hiredate from emp;

                                    select to_char(hiredate,'YYYY-MM-DD HH:MI:SS') FROM EMP;

                                    select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') FROM dual;

                                    select to_char(sysdate,'YYYY-MM-DD HH:MI:SS') FROM dual; //对日期的转换必须记住!

09:to_date函数:select ename,hiredate from emp where hiredate > '1981-2-20 12:34:54';

                                select ename,hiredate from emp where hiredate > to_date ('1981-2-20 12:34:54','YYYY-MM-DD HH24:MI:SS');

     to_number函数:select sal from emp where sal>to_number<'$1,250.00','$9,999.99'

     nvl函数(空值处理):select ename sal*12+NVL from emp;

10:select max(sal)/min(sal)/avg(sal) from emp;

   select to_char(avg(sal),'99999999.99') from emp;//数字转换成字符串

   select round(avg(sal),2) from emp;//四舍五入到小数点后面两位;

   select sum(sal) from emp;//支出薪水

   select count(*) from emp;//求出这个表总共有多少条记录

   select count(*) from emp where deptno = 10;//count<*>:count所有字段

   组函数:max,min,avg,sum,count//重点!必记!

   select count(ename) from emp;//count(ename):这个字段如果不是空值就算一个

   select count(distinct deptno) from emp;//去除重复值以后还有多少个部门编号

你可能感兴趣的:(Oracle笔记2)