Oracle-3 简单的入门

》》》》》》》》》》》》数据库表的导入导出《《《《《《《《《《
导出:
导出
导出
用户登录之后,可对数据库表导出保存,Tools–Export Tables…–选择要导出的表【不选的话默认选择全部表】–勾选上Create Tables–选择要保存的位置

导入:
导入
Tools–Import Tables…;

导入
选择您要导入的sql文件–import;

导入
导入成功

》》》》》》》》》》》》SQL语句《《《《《《《《《《
prompt PL/SQL Developer import file
prompt Created on 2018年7月28日 by ZQZ
set feedback off
set define off
prompt Creating DEPT…
create table DEPT
(
deptno NUMBER(2) not null,
dname VARCHAR2(14),
loc VARCHAR2(13)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
alter table DEPT
add constraint PK_DEPT primary key (DEPTNO)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);

prompt Creating EMP…
create table EMP
(
empno NUMBER(4) not null,
ename VARCHAR2(10),
job VARCHAR2(9),
mgr NUMBER(4),
hiredate DATE,
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(2)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
comment on column EMP.empno
is ‘员工编号’;
comment on column EMP.ename
is ‘员工姓名’;
comment on column EMP.job
is ‘职位’;
comment on column EMP.mgr
is ‘经理编号’;
comment on column EMP.hiredate
is ‘入职日期’;
comment on column EMP.sal
is ‘薪水’;
comment on column EMP.comm
is ‘奖金’;
comment on column EMP.deptno
is ‘所在部门编号’;
alter table EMP
add constraint PK_EMP primary key (EMPNO)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
alter table EMP
add constraint FK_DEPTNO foreign key (DEPTNO)
references DEPT (DEPTNO);

prompt Disabling triggers for DEPT…
alter table DEPT disable all triggers;
prompt Disabling triggers for EMP…
alter table EMP disable all triggers;
prompt Disabling foreign key constraints for EMP…
alter table EMP disable constraint FK_DEPTNO;
prompt Deleting EMP…
delete from EMP;
commit;
prompt Deleting DEPT…
delete from DEPT;
commit;
prompt Loading DEPT…
insert into DEPT (deptno, dname, loc)
values (10, ‘ACCOUNTING’, ‘NEW YORK’);
insert into DEPT (deptno, dname, loc)
values (20, ‘RESEARCH’, ‘DALLAS’);
insert into DEPT (deptno, dname, loc)
values (30, ‘SALES’, ‘CHICAGO’);
insert into DEPT (deptno, dname, loc)
values (40, ‘OPERATIONS’, ‘BOSTON’);
commit;
prompt 4 records loaded
prompt Loading EMP…
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7369, ‘SMITH’, ‘CLERK’, 7902, to_date(‘17-12-1980’, ‘dd-mm-yyyy’), 800, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7499, ‘ALLEN’, ‘SALESMAN’, 7698, to_date(‘20-02-1981’, ‘dd-mm-yyyy’), 1600, 300, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7521, ‘WARD’, ‘SALESMAN’, 7698, to_date(‘22-02-1981’, ‘dd-mm-yyyy’), 1250, 500, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7566, ‘JONES’, ‘MANAGER’, 7839, to_date(‘02-04-1981’, ‘dd-mm-yyyy’), 2975, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7654, ‘MARTIN’, ‘SALESMAN’, 7698, to_date(‘28-09-1981’, ‘dd-mm-yyyy’), 1250, 1400, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7698, ‘BLAKE’, ‘MANAGER’, 7839, to_date(‘01-05-1981’, ‘dd-mm-yyyy’), 2850, null, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7782, ‘CLARK’, ‘MANAGER’, 7839, to_date(‘09-06-1981’, ‘dd-mm-yyyy’), 2450, null, 10);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7788, ‘SCOTT’, ‘ANALYST’, 7566, to_date(‘19-04-1987’, ‘dd-mm-yyyy’), 3000, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7839, ‘KING’, ‘PRESIDENT’, null, to_date(‘17-11-1981’, ‘dd-mm-yyyy’), 5000, null, 10);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7844, ‘TURNER’, ‘SALESMAN’, 7698, to_date(‘08-09-1981’, ‘dd-mm-yyyy’), 1500, 0, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7876, ‘ADAMS’, ‘CLERK’, 7788, to_date(‘23-05-1987’, ‘dd-mm-yyyy’), 1100, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7900, ‘JAMES’, ‘CLERK’, 7698, to_date(‘03-12-1981’, ‘dd-mm-yyyy’), 950, null, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7902, ‘FORD’, ‘ANALYST’, 7566, to_date(‘03-12-1981’, ‘dd-mm-yyyy’), 3000, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7934, ‘MILLER’, ‘CLERK’, 7782, to_date(‘23-01-1982’, ‘dd-mm-yyyy’), 1300, null, 10);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7783, ‘CLARK’, ‘MAN_AGER’, 7839, to_date(‘09-06-1981’, ‘dd-mm-yyyy’), 2450, null, 10);
commit;
prompt 15 records loaded
prompt Enabling foreign key constraints for EMP…
alter table EMP enable constraint FK_DEPTNO;
prompt Enabling triggers for DEPT…
alter table DEPT enable all triggers;
prompt Enabling triggers for EMP…
alter table EMP enable all triggers;
set feedback on
set define on
prompt Done.

》》》》》》》》》》》》基本的select语句《《《《《《《《《《《《
选择所有列
* 代表emp表中的所有列
select * from emp;
select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp;(效率高)
查询
选中两张表,点击Execute(快捷键F8)

选择指定列
select ename,sal from emp;

》》》》》》》》》》》》算术运算符《《《《《《《《《《《《
将所有转正员工的薪资上调30%,查询员工转正后的薪资标准
select ename,sal,sal*1.3 from emp;

将所有转正员工的薪资上调30%,查询员工转正后的年薪(包括奖金在内,试用期6个月)
select ename,
sal 试用期工资,
sal * 1.2 转正后工资,
(sal * 6 * (1 + 1.3) + nvl(comm,0)) 年薪
from emp;
注意:null不是0不是空格” 与任意值做计算都返回null

》》》》》》》》》》》》列别名《《《《《《《《《《《《
select ename,sal newSal from emp;– 列名 别名
select ename,sal as newSal from emp;–列名 as 别名
–使用双引号的情况
select ename,sal “new sal” from emp;–有空格
select ename,sal “newSal” from emp; –区分大小写
select ename,sal “new_sal” from emp;–包含特殊字符

》》》》》》》》》》》》连接操作符 《《《《《《《《《《《《
select ename,job,(ename || ‘的职位是’ || job) 职位信息 from emp;
原义字符串 :一般用单引号”括起来 ,出现在每行数据当中 ,例如语句中的’的职位是’

》》》》》》》》》》》》消除重复行《《《《《《《《《《《《
select distinct deptno from emp; –消除deptno重复的数据行
select distinct job,deptno from emp; – 消除detpno、job都重复的数据

– 人生的意义在哪?是奋斗,奋斗的动力是什么,是代码实现功能之后的喜悦

– 愿您,天天开心❤

》》》》》》》》》》》》》》END《《《《《《《《《《《《《《《

猜你喜欢

转载自blog.csdn.net/qq_36090002/article/details/81261426