`
selinazzx
  • 浏览: 25442 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

SQL语句的总结(一)

阅读更多

     今天终于安装了oracle,终于试了一下,下面总结几个查询语句,不然会忘记。
    
     简单的我就不总结了,只总结感觉会忘记的东西。

(一)sql查询语句

1,null 表示空值
查询为空的语句:select * from emp where comm is null;
查询不为空的语句:select * from emp where comm is null;

2,多条件用and连接
select * from emp where comm<10 and sal<900;

3,!=和<>一样都表示不等于

4,between...and...查询范围
select * from emp where sal between 300 and 900;
等价于select * from emp where sal>=300 and sal<=900;

5,in操作指定具体范围的查询
select * from emp where sal in (300,400,500);

6,like的模糊查询
select * from emp where ename like '%a%';
注意:"%"匹配任意多个字符,"_"匹配任意一个字符

7,查询没有重复记录的
select distinct job from emp;

8,对结果进行排序
select * from emp where sal<10 order by sal asc,hiredate,desc:
注意:排序的代码写在整个SQL语句的最后;
      asc表示升序,desc表示降序,默认是asc
      先排序前面的(如sal),如果一样再按照后面的排序(如hiredate)

9,两个字段内容的连接操作||
select ename||'的工作是'||job from emp;
(二)单行函数

字符函数

1,转大写函数upper()
select upper('hello world') from dual;

2,转小写函数lower()
select lower('HELLO WORLD') from dual;

3,将单词首字母进行大写的函数initcap()
select initcap('hello world') from dual;

4,字符串连接函数concat(),等价于||
select concat('hello','world') from dual;

5,字符串截取函数substrate()
select substr('hello',0,3) from dual;
select substr('hello',1,3) from dual;
select substr('hello',-3,2) from dual;
注意:开始点从1和0开始都一样;
      第三句中 ‘-3’代表从最后数过来的第三位开始,
               ‘2’代表从倒数第三位开始正数往后两位
                结果输出“ll”

6,取字符串的长度length()
select length('hello') from dual; 

7,查找一个指定字符是否存在,返回器位置instr()
select instr('hello','e') from dual;

8,去掉左右空格trim()
select trim('   hello world    ') from dual;

9,替换字符replace()
select replace('hello','o','x') from dual;


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics