暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

小袁说项目(五)-创建源端测试用户和数据

yuanzj 2021-06-03
206

1.依次在orclpdb1,orclpdb2,orclpdb3,orclpdb4创建测试数据。

1.创建yuanzj用户,编写脚本

    [oracle@yuanzjora19c:/home/oracle/soft]$ vim yuanzj.sql
    [oracle@yuanzjora19c:/home/oracle/soft]$ cat yuanzj.sql
    create tablespace yuanzj datafile size 50m autoextend on next 50m maxsize 30g extent management local;
    create temporary tablespace yuanzj_temp tempfile size 50m autoextend on next 10m maxsize 30g;
    create user yuanzj identified by yuanzj123 default tablespace yuanzj temporary tablespace yuanzj_temp;
    grant connect,resource,create any view to yuanzj;
    grant execute on dbms_job to yuanzj;
    grant debug connect session to yuanzj;
    grant dba to yuanzj;
    alter profile default limit password_life_time unlimited;
    alter system set deferred_segment_creation=false;

    2.分别在orclpdb1,orclpdb2,orclpdb3,orclpdb4执行创建脚本(以orclpdb1为例)

      [oracle@yuanzjora19c:/home/oracle/soft]$ sqlplus sys/oracle_4U@orclpdb1 as sysdba


      SQL*Plus: Release 19.0.0.0.0 - Production on Fri May 28 19:30:58 2021
      Version 19.11.0.0.0


      Copyright (c) 1982, 2020, Oracle. All rights reserved.




      Connected to:
      Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
      Version 19.11.0.0.0


      SYS@orclpdb1> @yuanzj.sql


      Tablespace created.




      Tablespace created.




      User created.




      Grant succeeded.




      Grant succeeded.




      Grant succeeded.




      Grant succeeded.




      Profile altered.




      System altered.




      3.分别在orclpdb1,orclpdb2,orclpdb3,orclpdb4执行创建脚本创建测试数据

      a.在orclpdb1创建测试数据

        1、创建表test:
        create table test(
          id number(4) not null primary key,
          name varchar(25),
          age int
        );


        2、创建序列sql_test:
        create sequence seq_test
          increment by 4 --每次加几个
          start with 1 --从1开始计数
          nomaxvalue --不设置最大值
          nocycle --直累加,不循环
          cache 10 ;


        3、创建触发器tri_test:
        create trigger tri_test
        before insert on test for each row
        when (new.id is null)
        begin
        select seq_test.nextval into :new.id from dual;
        end;
        /
        4、像MSSQL中一样插入数据(不需要加ID)
        insert into test (name, age) Values ('yuanzj', 30);
        insert into test (name, age) Values ('yuanzj5', 30);


        b.在orclpdb2创建测试数据

          1、创建表test:
          create table test(
            id number(4) not null primary key,
            name varchar(25),
            age int
          );


          2、创建序列sql_test:
          create sequence seq_test
            increment by 4 --每次加几个
            start with 2 --从1开始计数
            nomaxvalue --不设置最大值
            nocycle --直累加,不循环
            cache 10 ;


          3、创建触发器tri_test:
          create trigger tri_test
          before insert on test for each row
          when (new.id is null)
          begin
          select seq_test.nextval into :new.id from dual;
          end;
          /
          4、像MSSQL中一样插入数据(不需要加ID)
          insert into test (name, age) Values ('yuanzj2', 30);
          insert into test (name, age) Values ('yuanzj6', 30);

          c.在orclpdb3创建测试数据

            1、创建表test:
            create table test(
              id number(4) not null primary key,
              name varchar(25),
              age int
            );


            2、创建序列sql_test:
            create sequence seq_test
              increment by 4 --每次加几个
              start with 3 --从1开始计数
              nomaxvalue --不设置最大值
              nocycle --直累加,不循环
              cache 10 ;


            3、创建触发器tri_test:
            create trigger tri_test
            before insert on test for each row
            when (new.id is null)
            begin
            select seq_test.nextval into :new.id from dual;
            end;
            /
            4、像MSSQL中一样插入数据(不需要加ID)
            insert into test (name, age) Values ('yuanzj3', 30);
            insert into test (name, age) Values ('yuanzj7', 30);


            1、创建表test:
            create table test(
              id number(4) not null primary key,
              name varchar(25),
              age int
            );


            d..在orclpdb4创建测试数据

              1、创建表test:
              create table test(
                id number(4) not null primary key,
                name varchar(25),
                age int
              );
              2、创建序列sql_test:
              create sequence seq_test
                increment by 4 --每次加几个
                start with 4 --从1开始计数
                nomaxvalue --不设置最大值
                nocycle --直累加,不循环
                cache 10 ;


              3、创建触发器tri_test:
              create trigger tri_test
              before insert on test for each row
              when (new.id is null)
              begin
              select seq_test.nextval into :new.id from dual;
              end;
              /
              4、像MSSQL中一样插入数据(不需要加ID)
              insert into test (name, age) Values ('yuanzj4', 30);
              insert into test (name, age) Values ('yuanzj8', 30);

              注意:注意观察每次个数据库里的序列

              文章转载自yuanzj,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

              评论