使用plsql添加数据并自动生成主键

步骤如下:

步骤一:新建需要创建的表如:

-- Create table create table IRC_SYS_DATADIC (

datadic_id VARCHAR2(64) not null,

datadic_key VARCHAR2(100),

datadic_val VARCHAR2(100),

datadic_module VARCHAR2(100),

datadic_mark VARCHAR2(100),

datadic_submodule VARCHAR2(100),

cre_time TIMESTAMP(6),

mod_time TIMESTAMP(6),

is_enable VARCHAR2(10),

reservel_var VARCHAR2(100),

reservel_num INTEGER )

tablespace CAAS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64 minextents 1 maxextents unlimited ); -- Add comments to the columns comment on column IRC_SYS_DATADIC.datadic_id is '数据字典主键id';

comment on column IRC_SYS_DATADIC.datadic_key is '数据字典对应的key值';

comment on column IRC_SYS_DATADIC.datadic_val is '数据字典对应的value值';

comment on column IRC_SYS_DATADIC.datadic_module is '数据字典所属的模块';

comment on column IRC_SYS_DATADIC.datadic_mark is '数据字典所对应的特殊标识';

comment on column IRC_SYS_DATADIC.datadic_submodule is '数据字典所属模块的子模块'; comment on column IRC_SYS_DATADIC.cre_time is '创建时间';

comment on column IRC_SYS_DATADIC.mod_time is '修改时间';

comment on column IRC_SYS_DATADIC.is_enable is '是否启用标识(启用为1,不启用为0)'; comment on column IRC_SYS_DATADIC.reservel_var is '预留字段字符型';

comment on column IRC_SYS_DATADIC.reservel_num is '预留字段数值型';

-- Create/Recreate primary, unique and foreign key constraints alter table IRC_SYS_DATADIC add constraint PK_DATADIC_ID primary key (DATADIC_ID) using index tablespace CAAS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited );

  步骤二:新建sequence

-- Create sequence create sequence SEQ_IRC_SYS_DATADIC minvalue 1 maxvalue 999999999 start with 21 increment by 1 cache 20;

步骤三:新建触发器

create or replace trigger TRI_IRC_SYS_DATADICr

before insert on IRC_SYS_DATADIC

for each row

declare begin select SEQ_IRC_SYS_DATADIC.nextval into :new.DATADIC_ID from dual;

end TRI_IRC_SYS_DATADICr;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值