• sql基本语句


     1.【select 查询 】

    /*查询标准语句*/

    select *  from  employees ;  /* select  查询列  from   表名; */

     

    /*查询姓名*/
    select s_name from employees;

    /*查询姓名,字段展示中文别名*/
    select s_name 姓名 from employees;

     2.【distinct去重】

    /*去重,去掉s_add中有重复的值*/
    select distinct  s_add  from employees;    /*select distinct  列  from 表;*/

    3.【连接字符  ||  ,双竖线】

        ‘ ’  单引号把字符串括起来。使用拼接符号拼接到一行显示

    /*字符串拼接*/
    select '姓名:' || ename || ',工作:' || job || ',入职时间:' ||  hiredate         员工信息表 from emp;

     

     

     

     

     

     4.【四则运算】

         +  - *  /   ,先乘除后加减,有括号的优先执行

      

    5.【别名】

      oracle起别名时尽量使用英文。

    6. 【where  条件查询】

        select  列  from  表 where 条件;

     7.【is not null / null】

         null空值  

     

      不为空   is not null   等价于 <> ' '         (注意<>' '   在单引号之间有空格)

     

     <>  和 !=    ,不等于

    <>只能判断空字符串,is Null是对Null字符的判断

    /*<>和!= 查询空值不出结果--不使用此方法判断空值*/
    select * from employees where school <> null;   /*sql查询错误*/
    select * from employees where school != null;   /*sql查询错误*/

    /*<>和!= 查询判断字符串*/
    select * from employees where school <>  '济南大学';
    select * from employees where school !=   '济南大学';

     8.【or 和 and】

       and 和,or 或

    9.【not】

        not:取反,假的

       可以使用括号表示一组的条件。

     10.【between .... and ....】

             语法:between  最小值  and  最大值

        除了查询数值,日期也可以查询

     11.【大小写问题】

          Oracle中对于英文的大小写是区分的,查询的时候要注意

       

     12.【in 和not in】

            in  /  not in  范围查询,字符串和数值都已使用in和not in

    13.【like】

          模糊查询,使用通配符: ' % '  ,  '_'  ,' [ ] ' ,'[^   ]' , 查询带有通配符字段

           注意要使用单引号

       %匹配任意类型、长度字符、字符串

        

        _ 单个字符,可以限制字符的长度

      [ ]   : 对于表中一列的一个字符、字符串或一定的范围,进行匹配他们的值。

      使用regexp_like ,(注:涉及到正则表达式)

      [^ ]   表示不在括号所列之内的单个字符

     

     带有通配符的需要使用转义字符 ESCAPE ,正斜杠 /  用来终止语句

    不怨天,不尤人;不迁怒,不贰过. 人一能之,己百之;人十能之,己千之. 做事要细心、热情、阳光,江湖处事就是人情世故。
  • 相关阅读:
    自定义 mapper
    solr 服务搭建
    jedis 连接redis
    jedis 整合 Spring
    Redis 安装
    HttpClient 工具类
    springMvc 中返回字符串 乱码解决
    linux常用命令解析
    压缩jar包
    控制反转
  • 原文地址:https://www.cnblogs.com/topzhangRX/p/9531681.html
Copyright © 2020-2023  润新知