今天初学oracle数据库,正好串起之前学过的Myeclipse的知识,复习也是进阶。
1、Oracle数据类型
1)number
2)char
3)varchar2
4)date
2、表控制语句
1)create table table_name()
2)drop table table_name;
3) alter table table_name;add(createdate column);4
4) insert into table_name;(属性) values (值);
5)update table_name;set 属性=值(欲修改), where 属性=值(条件);
3、oracle字符串操作
1)字符串合并:CONCAT和 ||
2)大小写转换:UPPER、LOWER和INITCAP
3)字符串截去:TRIM
4)字符串补位:LPAD、RPAD
5)字符串截取:SUBSTR
4、oracle数值操作
1)数值四舍五入:ROUND
2)数值截取:TRUNC
3)数值取余:MOD
5、oracle日期操作
1)select to_char(sysdate(当前时间),'yyyy-mm-dd day hh24:mi:ss') from dual
作用:将当前时间转换为2016-3-2 星期三 0:22:56 这样的格式
2)select to_date('2014-8-25','yyyy-mm-dd') from dual
作用:将字符串2014-8-25转换为默认格式:25-8-14 时间。
6、oracle修改默认日期格式:
alter session set nls_date_format='yyyy/mm/dd';
可以将当前会话oracle默认的日期格式'dd-mm-yy'转化为'yyyy/mm/dd';
接下来,用今天所学,实现一个数据表格:
create table emp(empno number(4,0) primary key,ename varchar2(10),
job varchar2(9),mgr number(4,0),hiredate date,sal number(7,2),comm
number(7,2),deptno number(2,0));
--1
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7369,'smith','clerk',7902,to_date('1980-12-17','yyyy/mm/dd'),
800.00,'',20);
commit;
--2
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7499,'allen','salesman',7698,to_date('1981-2-20','yyyy/mm/dd'),
1600.00,'300.00',20);
commit;
--3
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7521,'ward','salesman',7698,to_date('1981-2-22','yyyy/mm/dd'),
1250.00,'500.00',30);
commit;
--4
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7566,'jones','manager',7839,to_date('1981-4-2','yyyy/mm/dd'),
2975.00,'',20);
commit;
--5
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7654,'martin','salesman',7698,to_date('1981-9-28','yyyy/mm/dd'),
1250,'1400.00',30);
commit;
--6
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7698,'blake','manager',7839,to_date('1981-5-1','yyyy/mm/dd'),
2850,'',30);
commit;
--7
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7782,'clark','manager',7839,to_date('1981-6-9','yyyy/mm/dd'),
2450,'',10);
commit;
--8
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7788,'scott','analyst',7566,to_date('1987-4-19','yyyy/mm/dd'),
3000,'',20);
commit;
--9
insert into emp(empno,ename,job,hiredate,sal,comm,deptno) values
(7839,'king','president',to_date('1981-11-17','yyyy/mm/dd'),
5000,'',10);
commit;
--10
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7844,'turner','salesman',7698,to_date('1981-9-8','yyyy/mm/dd'),
5000,'0.00',30);
commit;
--11
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7876,'adams','clerk',7788,to_date('1987-5-23','yyyy/mm/dd'),
1100,'',20);
commit;
--12
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7900,'james','clerk',7698,to_date('1981-12-3','yyyy/mm/dd'),
950,'',30);
commit;
--13
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7902,'ford','analyst',7566,to_date('1981-12-3','yyyy/mm/dd'),
3000,'',20);
commit;
--14
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7934,'miller','clerk',7782,to_date('1982-1-23','yyyy/mm/dd'),
1300,'',10);
commit;
select empno as "员工ID",ename as "员工姓名", job as "职位",mgr as "员工管理者ID",
hiredate as "入职日期",sal as "薪资",comm as "绩效",deptno as "员工所在部门的ID"
from emp;
alter session set nls_date_format='yyyy/mm/dd';
表格如下: