在Oracle数据库创建脚本中如何初始化某些表

Sample

 

表空间:IMPTEMP

表:Roles 、Users

 

通过PL/SQL导出的数据库脚本

-----------------------------------------------------
-- Export file for user IMPTEMP                    --
-- Created by Administrator on 2010-1-29, 14:14:25 --
-----------------------------------------------------

spool sample.log

prompt
prompt Creating table ROLES
prompt ====================
prompt
create table IMPTEMP.ROLES
(
  ROLENAME NVARCHAR2(50) not null,
  ROLEXML  NCLOB
)
tablespace IMPTEMP
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table IMPTEMP.ROLES
  add constraint ROLES_PRIMARY_KEY primary key (ROLENAME)
  using index
  tablespace IMPTEMP
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table USERS
prompt ====================
prompt
create table IMPTEMP.USERS
(
  USERID   NVARCHAR2(50) not null,
  USERNAME NVARCHAR2(50),
  ROLENAME NVARCHAR2(50),
  PASSWORD NVARCHAR2(50),
  USERXML  NCLOB,
  USERDN   NVARCHAR2(100),
  ISLOCAL  NUMBER(1)
)
tablespace IMPTEMP
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
comment on column IMPTEMP.USERS.ISLOCAL
  is '0-ISNOTLOCAL  :  1-ISLOCAL';
alter table IMPTEMP.USERS
  add constraint USERS_PRIMARY_KEY primary key (USERID)
  using index
  tablespace IMPTEMP
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );


spool off

 

现在要为Users表初始化一条userid为“admin”的人员,为Roles表初始化一条rolename为‘超级管理员’的角色,修改脚本如下:

-----------------------------------------------------
-- Export file for user IMPTEMP                    --
-- Created by Administrator on 2010-1-29, 14:14:25 --
-----------------------------------------------------

spool sample.log

prompt
prompt Creating table ROLES
prompt ====================
prompt
create table IMPTEMP.ROLES
(
  ROLENAME NVARCHAR2(50) not null,
  ROLEXML  NCLOB
)
tablespace IMPTEMP
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table IMPTEMP.ROLES
  add constraint ROLES_PRIMARY_KEY primary key (ROLENAME)
  using index
  tablespace IMPTEMP
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );


insert into IMPTEMP.ROLES t values('超级管理员','<?xml version="1.0" encoding="GBK"?><RoleInfo><RoleName>超级管理员</RoleName><RightList><Right>显示任务</Right><Right>查看配置</Right><Right>查看资源</Right><Right>节目流程管理</Right><Right>任务操作</Right><Right>Interplay资源发送</Right><Right>Interplay资源删除</Right><Right>创建ISIS Workspace</Right><Right>删除ISIS Workspace</Right><Right>基本配置</Right><Right>用户与角色</Right><Right>模板定义</Right><Right>设备工位</Right><Right>系统服务</Right><Right>多点登录</Right><Right>送审送播</Right></RightList></RoleInfo>');

prompt
prompt Creating table USERS
prompt ====================
prompt
create table IMPTEMP.USERS
(
  USERID   NVARCHAR2(50) not null,
  USERNAME NVARCHAR2(50),
  ROLENAME NVARCHAR2(50),
  PASSWORD NVARCHAR2(50),
  USERXML  NCLOB,
  USERDN   NVARCHAR2(100),
  ISLOCAL  NUMBER(1)
)
tablespace IMPTEMP
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
comment on column IMPTEMP.USERS.ISLOCAL
  is '0-ISNOTLOCAL  :  1-ISLOCAL';
alter table IMPTEMP.USERS
  add constraint USERS_PRIMARY_KEY primary key (USERID)
  using index
  tablespace IMPTEMP
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );

insert into IMPTEMP.USERS t values('admin','admin','超级管理员','admin','<?xml version="1.0" encoding="GBK"?><UserInfo><UserID>admin</UserID><ExtraInfo></ExtraInfo></UserInfo>','','0');
spool off

 

此处需要说明的是,插入语句与平时使用的sql语句一样,唯一不同的是需要在语句最后加分号“;”,否则该句不会被执行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值