指点成金-最美分享吧

登录

oracle基础函数

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了oracle基础函数相关的知识,希望对你有一定的参考价值。

用scott用户登陆oracle自带四张表,用于练习 

输入 select * from tab; 可以看到4张表:emp,bonus,dept,salgrade  (* 代表查询整张表)

 

1、降序排序[Order by (desc) ]

Select ename,sal from emp order by sal desc;【查询emp表,根据sal字段进行降序】

Select ename,sal from emp order by sal ;【查询emp表,根据sal字段进行升序】

 

2、SQl条件查询

Where【where关键字后边写查询条件】

Select ename,sal  from emp where sal >1000 and sal <1500 order by sal desc ;

Select ename,sal  from emp where sal <1000 or sal >1500 order by sal desc ;

 

 

3、Between and 【在…之间】

Select ename ,sal from emp where sal between 1000 and 1500;

4、In【在…..值】

select ename from emp where sal in (800,1600); 结果SMITH,ALLEN

 

5、Like【在表示判断时,like和 = 的作用相同,但是like可以做模糊查询,= 不能做模糊查询】

5.1,  select * from emp where ename like "SMITH";

5.2,  模糊查询【概念:按照不确定的信息查询数据】

例:  select * from emp where ename like "%MI%’;

 

5.3Not like【可理解成不等于某个值,与!= 或< >作用相同】

select * from emp where ename not like "SMITH"

 

6、"=’【表示判断】

select * from emp where ename = "SMITH";

 

And【并列的含义,可以直接翻译成并且】

Or【非并列的含义,可以直接翻译成或者】

 

 

 

7、字段别名的使用【用as 别名切记要用双引号 as可写可不写】

select ename as "姓名" from emp【as 可有可无】

select ename "Xing Ming" from emp

 

备注:字段别名就是修改显示出来的字段名

 

8、字段运算【可以有 +  -   *  /  的运算】

Select  sal+100  “总和”  from emp where ename = "SMITH’

Select  sal/100   from emp where ename = "SMITH’

Select  sal*100  from emp where ename = "SMITH’

 

Select ename + 100 from emp…….

【这样是没意义的,因为字段类型不一致,字符串类型不能与数字类型相加】

 

9、函数的使用

Sum【求和函数,对某一列进行求和】

 

 

10、Avg【求平均值,对某列求平均值】

 

 

11、Max【最大值,对某列求最大值】

 

 

12、Count(*)【求数量,对对某个表计算行数】

13、Group by 【分组函数,一般group by 需要配合 max,sum,avg,count(*)一起使用】

 

 Having【只能和group by 配合使用 】

 

 

 

14、Lower【大写转小写】

 

 Upper【小写转大写】

 

 

15、Concat【字符串拼接函数,一般用在SQL语句中】

      ||   【字符串拼接函数,一般用在PL/SQL程序中】

 

 

 

 dual  (虚拟表,数据库内置表)

 

 16、Substr(ename,1,2)【求某个字符串当中的子串】

(1代表起始位置,2代表子串长度)

 

17、Instr(ename,’n’)【子串在主字符串的下标】

 

 

18、Initcap 【首字母改大写,其他字母小写】

 

 

 

19、Length(求字符长度)

 

 

 

 

20、Lengthb(字节个数)

 

 

 

 

一个汉字是一个字符两个字节

 

以上是关于oracle基础函数的主要内容,如果未能解决你的问题,请参考以下文章