阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle模拟业务最小测试用例

102次阅读
没有评论

共计 2647 个字符,预计需要花费 7 分钟才能阅读完成。

环境:RHEL6.4 + Oracle 11.2.0.4

  • 1. 创建业务用户表空间
  • 2. 创建业务用户
  • 3. 赋予用户权限
  • 4. 创建业务表
  • 5. 创建索引
  • 6. 业务查询 SQL
  • 7. 删除业务用户及数据
  • 8. 删除业务表空间

1. 创建业务用户表空间

  • 假设使用了 OMF 管理,不需要明确指定数据目录 (判定是否使用了 OMF 技术,查看 db_create_file_dest 参数配置:show parameter db_create_file_dest)

    -- 数据表空间 
    create tablespace dbs_d_jingyu datafile size 30M autoextend off;
    -- 临时表空间 
    create temporary tablespace temp_jingyu tempfile size 30M autoextend off;
    -- 索引表空间 (可选)
    create tablespace dbs_i_jingyu datafile size 30M autoextend off;
  • 假设文件系统管理,且未使用 OMF 管理,规划的数据目录是 /oradata1

    -- 数据表空间 
    create tablespace dbs_d_jingyu datafile '/oradata1/datafiles/dbs_d_jingyu01.dbf' size 30M autoextend off;
    -- 临时表空间 
    create temporary tablespace temp_jingyu tempfile '/oradata1/tempfiles/temp_jingyu01.tmp' size 30M autoextend off;
    -- 索引表空间 (可选)
    create tablespace dbs_i_jingyu datafile '/oradata1/datafiles/dbs_i_jingyu01.dbf' size 30M autoextend off;
  • 假设 ASM 磁盘组,指定磁盘组是 +DATA,具体路径 OMF 管理

    -- 数据表空间 
    create tablespace dbs_d_jingyu datafile '+DATA' size 30M autoextend off;
    -- 临时表空间 
    create temporary tablespace temp_jingyu tempfile '+DATA' size 30M autoextend off;
    -- 索引表空间 (可选)
    create tablespace dbs_i_jingyu datafile '+DATA' size 30M autoextend off;

2. 创建业务用户

-- 假设创建用户 jingyu 密码 jingyu,默认临时表空间 temp_jingyu,默认数据表空间 dbs_d_jingyu。
CREATE USER jingyu IDENTIFIED BY jingyu
  TEMPORARY TABLESPACE temp_jingyu
  DEFAULT TABLESPACE dbs_d_jingyu
  QUOTA UNLIMITED ON dbs_d_jingyu;

3. 赋予用户权限

-- 赋予普通业务用户权限 
grant resource, connect to jingyu;
-- 赋予 DBA 用户权限 
grant dba to jingyu;

4. 创建业务表

新建业务用户登录,创建 T1,T2 两张业务表,并插入测试数据。

-- 业务用户登录 
conn jingyu/jingyu
-- 删除 T1,T2 两张表 
drop table t1 cascade constraints purge;
drop table t2 cascade constraints purge;
-- 创建 T1,T2 两张表 
create table t1(id number not null, n number, contents varchar2(4000) ) tablespace dbs_d_jingyu;
create table t2(id number not null, t1_id number not null, n number, contents varchar2(4000) ) tablespace dbs_d_jingyu;
-- 初始化向 T1,T2 表插入随机测试数据 
execute dbms_random.seed(0);
set timing on
insert into t1  select rownum, rownum, dbms_random.string('a',50)   from dual   connect by level <= 100   order by dbms_random.random;
commit;  
insert into t2  select rownum, rownum, rownum, dbms_random.string('b',50)  from dual  connect by level <= 100000  order by dbms_random.random;
commit;
-- 查询 T1,T2 表数据量 
select count(1) from t1;
select count(1) from t2;

5. 创建索引

-- 创建 T1 表字段 n 的索引 idx_t1_n
create index idx_t1_n on t1(n) tablespace dbs_i_jingyu;
-- 创建 T2 表字段 id 的索引 idx_t2_t1id
create index idx_t2_t1id on t2(t1_id) tablespace dbs_i_jingyu;

6. 业务查询 SQL

-- 业务查询 SQL 1
select * from t1, t2 where t1.id = t2.t1_id and t1.n = 19;
-- 业务查询 SQL 2
select * from t1, t2 where t1.id = t2.t1_id;

7. 删除业务用户及数据

-- 删除业务用户 jingyu
drop user jingyu cascade;

8. 删除业务表空间

-- 删除数据表空间及其文件 
drop tablespace dbs_d_jingyu including contents and datafiles;
-- 删除索引表空间及其文件 
drop tablespace dbs_i_jingyu including contents and datafiles;
-- 删除临时表空间及其文件 
drop tablespace temp_jingyu including contents and datafiles;

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-08/134556.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计2647字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中