查询练习一
表创建
create table employee as select * from soctt.emp ;
sysdba用户登录
grant select on scott.emp to $username$
create table empployee_demo(
empno number(4) not null primary key,
ename varchar2(10) not null unique,
job varchar2(9),
mgr number(4),
hiredate date default sysdate,
sal number(7,2) check(sal>=500 and sal<=10000),
comm number(7,2),
deptno number(2)
)
select * from employee where last_day(hiredate)-2=hiredate;
select * from employee where months_between(hiredate,sysdate)/12>25;
select * from employee where year(sysdate)-year(hiredate)>25;
select upper(substr(ename,0,1))||lower(substr(ename,1)) from employee;
select nls_initcap(ename) from employee;
select initcap(ename) from employee;
select lower(substr(ename,1,1))||upper(substr(ename,2)) from employee;
select ename from employee where length(ename)=5;
select ename from employee where ename not like '%R%';
select substr(ename,1,3) from employee
select replace(ename,'a','A') from employee;
select ename,hiretate from employee where months_between(hiredate,sysdate)/12 >=25
select * from employee order by ename,sal desc;
select ename,hiredate,months_between(hiredate,sysdate)
from employee
order by months_between(hiredate,sysdate)
select ename,hiredate,months_between(sysdate,hiredate)
from employee
order by months_between(sysdate,hiredate) desc
select ename,job,sal from employee
order by job,sal;
select ename,JOB,TO_CHAR(hiredate,'yyyy') year,
TO_CHAR(hiredate,'mm') month
from employee
order by month,year;