java 从零开始,学习笔记之基础入门(Oracle_基础)(三十三)(二)

2014-11-24 07:51:16 · 作者: · 浏览: 1
果的记录行数

selectrownum,ename from scott.emp

--采用运算符,即+,-,*,/查询结果会出现多的一列,此为计算后形成的,成为计算列

select ename,sal,sal+2000as计算列from scott.emp;

--as作为列名与别名的连接,as也可以省略,如果遇到特殊字符或空格,需要将别名用引号包起来

select ename 员工,sal 工资from scott.emp

select ename as Name,sal*1.5as 员工工资(加年终奖) from scott.emp;

--使用||做连接两个字符串

select ename||job as员工和职位from scott.emp

select ename || ' is ' ||job as员工和职位from scott.emp;

--消除重复的行

selectdistinct job from scott.emp

selectdistinct deptno from scott.emp

--排序,order by 默认采用升序,如果要采用降序,必须制定

select ename,sal from scott.emp orderby sal desc

--多列排序,先按照第一列,然后依次往下

select ename,sal,hiredate from scott.emp orderby sal,hiredate

--对计算列进行排序,对其指定别名

select empno,ename,sal*Months_between(sysdate,hiredate) as total from

scott.emp orderby total;

--条件查询,条件格式是放在where 关键字后面

--中文日期格式为DD-MM月-yy

select ename,hiredate from scott.emp where hiredate >='1-1月-1982';

--多条件查询

select * from scott.emp where (deptno=10or deptno=20) and sal<1500;

--like 模糊查询,%代表0个或者多个任意的字符,”下划线代表一个任意字符“

select ename from scott.emp where ename like'A%'

SELECT * FROM SCOTT.EMP WHERE ENAME LIKE'A____'

select * from scott.dept;