drop table EMP cascade constraints;
/*==============================================================*/
/* Table: EMP */
/*==============================================================*/
create table EMP (
ID INTEGER not null,
REALNAME varchar2(50),
LOGINNAME varchar2(50),
DEPTID integer not null,
constraint PK_EMP primary key (ID)
);
comment on table EMP is
'员工';
comment on column EMP.ID is
'主键编号';
comment on column EMP.REALNAME is
'真实名';
comment on column EMP.LOGINNAME is
'登录名';
comment on column EMP.DEPTID is
'所属部门';
drop table DEPT cascade constraints;
/*==============================================================*/
/* Table: DEPT */
/*==============================================================*/
create table DEPT (
DEPTID integer not null,
DEPTNAME varchar2(50) not null,
constraint PK_DEPT primary key (DEPTID)
);
comment on table DEPT is
'部门';
comment on column DEPT.DEPTID is
'部门主键';
comment on column DEPT.DEPTNAME is
'部门名';
--创建视图
select * from emp;
select * from dept;
create or replace view emp_v
as
select e.id,e.realname,e.loginname,e.deptid,t.deptname from emp e,dept t where e.deptid=t.deptid;
create or replace view dept_v
as
select * from dept;
--创建序列
drop SEQUENCE emp_seq;
drop SEQUENCE dept_seq;
CREATE SEQUENCE emp_seq
INCREMENT BY 1 -- 每次加几个
START WITH 10000 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
CREATE SEQUENCE dept_seq
INCREMENT BY 1 -- 每次加几个
START WITH 10000 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
select emp_seq.nextval from dual;
select dept_seq.nextval from dual;
--创建触发器
create or replace trigger emp_v_t
INSTEAD OF INSERT or update or delete ON emp_v FOR EACH ROW
begin
if inserting then
insert into emp(id,realname,loginname,deptid) values(emp_seq.nextval,:new.realname,:new.loginname,:new.deptid);
end if;
if updating then
update emp set realname=:new.realname,loginname=:new.loginname,deptid=:new.deptid where id=:old.id;
end if;
if deleting then
delete emp where id=:old.id;
end if;
end;
create or replace trigger dept_v_t
INSTEAD OF INSERT or update or delete ON dept_v FOR EACH ROW
begin
if inserting then
insert into dept(deptid,deptname) values(dept_seq.nextval,:new.deptname);
end if;
if updating then
update dept set deptname=:new.deptname where deptid=:old.deptid;
end if;
if deleting then
delete dept where deptid=:old.deptid;
end if;
end;
--测试数据
insert into dept_v(DEPTNAME) values('软件部')
update dept_v set deptname='软件部' where deptid=10001
insert into emp_v(realname,loginname,deptid) values('胡博维','hubowei',10001)
select * from emp;
select * from emp_v;
select * from dept;
select * from dept_v;
Select user_name,sql_text from V$open_cursor where user_name='weidu';
分享到:
相关推荐
普及一下oracle的基础知识,总结一下,oracle 是由实例和数据库组成。结构如下: oracle数据库由实例、数据库组成: * 数据库由数据文件(包含oracle 数据、索引、表结构等数据)、控制文件(包括每个表的操作信息...
oracle数据库报错ORA-00257: archiver error. Connect internal only, until freed ,如何解决呢?此问题定位在归档日志满了,下面把具体解决办法总结分享给大家。 解决办法: SQL> select * from V$FLASH_RECOVERY_...
如:“AREA”,如果查询的是个人地理数据库数据,则需要将字段名包含在方括号内,如:[AREA],如果查询的是ArcSDE地理数据库数据或是ArcIMS要素类或ArcIMS影象服务子层中的数据,则不需要将字段名括起,如:AREA ...
第一章 AIX操作系统简介 8 1.1 AIX操作系统的主要特点 8 1.1.1 遵循众多工业标准 8 1.1.2 先进的系统设计 8 1.1.3 强大的通讯能力 9 1.1.4 终端支持 9 ...第二十章 关系数据库(INFORMIX)的管理技巧 172