Oracle在pl/sql中操作基本表 记录
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
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