oracle使用中的一些问题

时间:2024-05-02 00:17:40

一、设置自增主键(假设表的主键名为:company_id)

1)创建序列(company_autoinc):

 create sequence company_autoinc  minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
nocache;

2)创建触发器(company_trigger):

 create or replace trigger company_trigger
before insert on sl_company
for each row
declare
-- local variables here
begin
select company_autoinc.nextval into :new.company_id from dual;
end company_trigger;

注意:执行触发器时语句时可能会提示用户权限不足,这时需要使用最高权限的管理员登陆,登陆方式为SYSDB,登录后左侧菜单中找到user菜单,为用户添加或修改权限。