oracle查询sql语句

一.模糊查询

1.关键字   like

2  通配符( —,%)

一个—只能代表一个字符,

%可以代替0到多个字符。

select * from user where username='%a_';

二.范围查询

between ......and.....

select * from   users  where salary  between  800 and  2000;

查询结果包含800也包含2000.

in/not in

in后面是具体值,而不是范围

三,对结果排序

order by........DESC(降序)/ASC(升序)

四,case........when语法的使用

1.    case    column_name  when  value1   then  result1,..... .[else  result]  END

     例子:select username,case username  when 'aaa' then '计算机部门'

                when 'bbb' then'市场部门'   else '其他部门'  end  as'其他部门'

                as'部门' from users

2.   case     when     column1=value1   then  result1,..... .[else  result]  END

             

   例子:select username,case  when username=' aaa' then '计算机部门'

                when username='bbb' then '市场部门'   else '其他部门'  end  as'其他部门'

                as'部门' from users

五,decode函数的使用

decode(column_name,value1,result1,...........defaultvalue)

select  username,decore(username,'aaa','计算机部门',‘bbb’,'市场部门',‘其他’)as 部门 from users

猜你喜欢

转载自blog.csdn.net/libaowen609/article/details/82917908