您的位置:首页 > 数据库 > Oracle

Oracle在pl/sql中操作基本表 记录

2017-09-15 15:40 501 查看
drop table customers--删除表

create table customers(id integer  primary key not null, name varchar(15));--创建一个表如customers

DROP sequence customers_ID_SEQ;--删除序列

--创建序列seq_后面是表名

create sequence seq_customers

minvalue 1

nomaxvalue

start with 1

increment by 1

nocycle   --一直累加,不循环

--nocache;  --不缓存

cache 10; --缓存10条

DROP TRIGGER tr_customers;--删除触发器

--创建触发器,如果insert语句不指定ID自动插入增长值tr_后面是表名

CREATE OR REPLACE TRIGGER tr_customers

BEFORE INSERT ON customers FOR EACH ROW WHEN (new.id is null)

begin

select seq_customers.nextval into:new.id from dual;

end;

insert into customers(name)values('dsad'); --如果创建了序列和触发器,则此处不需要再指定id的值,自动累加执行

delete from customers

select * from customers

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: