门道笔记 (1) oracle

  --我们的系统的库是哪个?

    orcl
  --我们系统的表有哪些?

    table
  --我要熟悉我们的系统?

    熟悉字段和字段的信息

    salary薪水

    commision 佣金

    上班后公司的表会多,测试先熟悉对应的模块的表和表结构。

  ***************************************************

  测试人员用的最多的是查询数据

  ***************************************************

  1、查询一个字段

    select ename from emp ;

    execute--F8 --执行

    new sql window 来书写语句。

    --写完一句sql语句就分号结束。

  2.查询多个字段 

    select ename,sal,comm,deptno from emp;

    --都好分隔字段,最后一个字段没有逗号。

  3.查询所有字段 * 

    select * from emp ;

  4.运算     注意 NVL(字段,默认值(缺省值))

    select sal*12 from emp;

    select ename *12 from emp ;--无效的字段

  *************************************************

    select sal,comm,sal+nvl(comm,0),(sal+nvl(comm,0))*12 from emp ;

    --当运算时字段中有空值,运算结果就是空值,oracle用nvl函数处理

    工作后,遇到运算小心,随时可能遇到NVL

  5.别名  alias===> as 不能中文、见名知意

    1.字段别名

      意义:当字段很长的,记不住,展示起来用户看不懂。

      select sal,comm,sal+nvl(comm,0) as 月薪 ,(sal-nvl(comm,0)*12 as 年薪 from emp ;

      select e.ename,sal,(sal+nvl(comm,0))*12 year_sal from emp e;  mouth_salary

    2.表别名 不能写as

      意义:某个表,字段多,长,写起来会炸

      我们通过给表取一个别名号,通过别名  .  出来(先from dept d出别名)

      select e.* from emp e ;

    ****************************************************

    字段别名是为了给客户方便看字段,表别名

    是为了写sql时,记不住字段别名但又要快速

    写sql时使用。

    ******************************************************

    where:

    语法:

    select 字段

    from 表

    where 条件condition

    ******************************************************

  看表习惯:条件反射

    当我打开一个表时,我会马上去看字段中的数据的类型,从而根据这个类型去想到如何去处理

    读的习惯:反向读sql语句

  1.数字

    1、>,<,=,>=,<=,<>,!=     --select ename from emp where sal>2000;

    2、between...and...  --select ename from emp where between 2000 from 3000;

  2.字符串

    1、= 

      --select * from emp where ename='SCOTT';

    2、like 

      --select * from emp where ename like '%N%';--记住这个就可以了

              %:匹配0个或多个字符

       _:匹配一个字符

      --还有一些妖孽的玩法,工作中遇到的不都;--张%、_ _M_ _ _(只能六个字符长度并且第三个字符为M)、_ _M_ _ _%、%_ _ M_ _ _%(至少有7个字符,且M前面有两个字符,且M后面有三个字符)

    3、空值 is  null

      select * from emp where comm is null;

    4、一串值 :当我们要取某列种的某些数据 in

        select sal from emp where ename in ('SMITH','SCOTT','菜10','凤姐','范bb');

    5、取反 not

      in   /  not  in

      like /  not  like

      between..and / not between..and..

      is nul  / is not null   isn't null 的错是因为没有成对出现单引号,当然他本身也是错误。

  *****************************and  or  not *********************报表测试就是sql测试

    and取交集,随着and 的增加,数据会越来越少,工作中,面对的几乎都是and操作

    select * from emp where sal >2000 and deptno in(10,30)

    or取的是并集,随着or的增加,数据会越来越多

  ********************************你有可能遇到*********************************

    select from ... where (...and...and...)or(....and.... )or(....and... ) and的优先级高于or

     格式处理使用beautifier按键;遇到and和or同时存在时,建议使用()把数据分离开,这样有利于你看懂语法和进行代码调试。

少壮不努力,老大徒伤悲
原文地址:https://www.cnblogs.com/zsjlovewm/p/10430924.html