sql笔记(来自oracle 的scott用户)

1.区分sql命令和sqlplus(oracle提供)-->sql不能缩写,sqlplus能够java

2.mysql 不区分字符串的大小写, oracle区分mysql

3.oracle 查询系统参数设置 : select * from v$nls_parameters;sql

      alter session set parameter ='  ';数据库

空值问题:session

   (1)null !=null  数据库中null是未赋值的意思,不是表明空格或0oracle

   (2)若是集合中含有null ,不能使用 not in 但能够使用in 函数

如: select * from emp where deptno not in(10,20,null)-->错误性能

5ebda8c0-3b4d-4f63-9b76-7599bc1465f5

   (3)组函数会自动滤空,能够嵌套滤空函数来屏蔽.net

如:comm中含有10个空值3d

       count(*)为15行记录

       count(comm)为5行记录(已经滤空值)

4.查询带有下滑线的名字-->select * from table where name like '%\_%' escape '\' ;

5.desc 排序只做用于 最近的一列

6.排序时null在最后 select * from table order by comm desc nulls last(只能在oracle中)

7.ROUND--> 四舍五入   TRUNC截断  MOD求余

8:条件表达式

       在sql语句中使用IF-THEN-ELSE逻辑

       使用两种方法:

          CASE表达式:SQL99的语法,相似basic ,比较繁琐

select ename,job,sal 涨前,

                 case job when 'PRESIDENT' then sal+1000

                          when 'MANAGER' then sal+800

                          else sal+400

                 end 涨后

from emp;

          DECODE函数:Oracle本身的语法,相似java,比较简洁

select ename,job,sal 涨前,

                 decode(job,'PRESIDENT',sal+1000,

                                    'MANAGER',sal+800,

                                                       sal+400) 涨后

from emp

9:where 和having的区别-->where 条件中不能有组函数

10:group by 语句的加强

  group by deptno , job

     +group by deptno

     +group by null

     =

     group by rollup(deptno,job)

抽象:

    group by rollup(a,b) = group by a,b

                                        +group by a

                                        +group by null

81991f7b-9e51-48a7-a906-244a919008a1

11:笛卡尔全集:两张 表的列数相加行数相成,应该尽可能使用链接条件,避免使用笛卡尔全集,由于笛卡尔全集中 可能有错误

004ae564-8d42-434c-a134-980613d38145

12:8f99c45a-5b6a-4819-a506-11bb7cd49d29

13:注意,自链接有性能问题(所产生的笛卡尔集是表记录的平方,若是有1亿条记录,呵呵~)

63b8ef15-79b4-4caf-b212-08ba342c5edc

14:层次查询,当你查询的数据是一颗树的时候,使用层次查询取代自链接

23370753-31d4-43b4-8d15-67a475b8b9a2

     (1)伪列表示节点深度(能够不写)

select level , empno, ename, mgr

from emp

connect by prior empno=mgr 

start with mgr is null  (根节点)

order by empno

/

15

a43d43dc-1b16-462e-b80f-08330b7b636d

c09837f5-1c12-40a3-a301-8ba34fa2c284

16:

931a36a6-d56b-4446-841f-d2eda018893a

17:

e1a19b0e-b723-42a9-b9c3-fcc9f9e967ac

18:

b7c2203b-74c2-45da-ab82-987feaa86985

19:

44b67e7b-f559-4600-b8ff-f1f5c6b4852b

相关文章
相关标签/搜索