DBLOG
» WTF
Toggle navigation
DBLOG
主页
OCM
1、概览
2、数据导入导出
3、GaussDB(DWS)数据库管理
4、数据库调优与开发实践
5、湖仓一体
6、开发应用
7、集群管理
8、巡检和维运维
About Me
归档
标签
S4
无
2025-03-12 09:19:08
12
0
0
admin
# Skillset 4 (110 min) ## DESCRIBE 数据文件可以自动扩展,但不能超过2G; Database Name User/Password 数据库名称 用户/密码 - PROD1 sh/sh、hr/hr、oe/oe、oltp_user/oltp_user1、sys/oracle、system/oracle - PROD2/PROD3 sys/oracle、system/oracle - PROD4 sys/oracle、system/oracle、rc_admin/RC_ADMIN - EMREP sys/Oracle123、system/Oracle123、sysman/Oracle123 ## Tasks 任务 ### Section 1: Create an Additional Buffer Cache ### 第一部分:创建附加的缓冲缓存 1.1. Create an additional buffer cache within the SGA of the PROD1 database for use with 16 KB blocks. Ensure that the 16 KB buffer cache is always available in the SGA. 在PROD1数据库的SGA中创建一个附加的缓冲缓存,使用16 KB的块。确保16 KB缓冲缓存始终在SGA中可用。 ``` -- 修改系统参数,设置16KB缓冲缓存大小为15MB alter system set db_16k_cache_size=15m; -- 设置db_16k_cache_size参数,将16KB缓冲缓存的大小设为15MB -- 显示与16KB缓存相关的所有参数 show parameter 16k; -- 显示所有与16K缓存相关的数据库参数信息 ``` ### Section 2: Optimize the Space Usage for LOB Data ### 第二部分:优化LOB数据的空间使用 2.1. Create a table in the PROD1 database to optimize the space usage for multiple rows that can have the same LOB data and also compress the LOB data. 在PROD1数据库中创建一个表,以优化可以具有相同LOB数据的多行的空间使用,并压缩LOB数据。 2.1.1. Create a tablespace `sf_tbs`,Use the following specifications: 创建一个表空间`sf_tbs`,使用以下规格: - File size of 150MB , Initial extent size of 64MB , next extent size of 64MB. 文件大小为150MB,初始范围大小为64MB,下一个范围大小为64MB。 ``` create tablespace sf_tbs datafile '/u01/app/oracle/oradata/PROD1/sf_tbs01.dbf' size 150M autoextend on maxsize 2G extent management local uniform size 64M; ``` 2.1.2. As the OE user, create the `TEST_SPEC` table in the `SF_TBS` tablespace with the following columns: 作为OE用户,在`SF_TBS`表空间中创建`TEST_SPEC`表,包含以下列: - ID NUMBER, - DOC BLOB. 启用DOC列的压缩,并通过避免多份相同LOB数据来节省空间。 ``` -- 设置数据库参数 db_securefile 为 PERMITTED -- 这个参数控制是否允许使用 SecureFile LOBs,选项包括: -- - NEVER: 不允许使用 SecureFile LOB。 -- - PERMITTED: 允许使用 SecureFile LOB,但如果没有满足条件,则使用普通 LOB。 -- - ALWAYS: 始终使用 SecureFile LOB。 ALTER SYSTEM SET db_securefile = PERMITTED; -- 显示当前 db_securefile 参数的值 SHOW PARAMETER db_securefile; -- 解锁用户 oe,并将其密码设置为 oe ALTER USER oe IDENTIFIED BY oe ACCOUNT UNLOCK; -- 使用 oe 用户连接到数据库 CONN oe/oe; -- 创建一个名为 test_spec 的表 -- 表包含两个列: id(数字类型)和 doc(BLOB 类型) -- 存储在表空间 sf_tbs 中,使用 SecureFile LOB 存储 doc 列 -- 并启用去重和高压缩 CREATE TABLE test_spec ( id NUMBER, -- id 列,数值类型 doc BLOB -- doc 列,二进制大对象(BLOB),用于存储二进制数据 ) TABLESPACE sf_tbs -- 指定表空间为 sf_tbs LOB(doc) STORE AS -- 指定 LOB 存储选项 SECUREFILE ( -- 使用 SecureFile LOB 存储 DEDUPLICATE, -- 启用去重,减少存储空间 COMPRESS HIGH -- 使用高压缩级别,节省存储空间 ); ``` 2.1.3. Create OS directory `/home/oracle/scripts/cust_files` and point to directory `dir_dmp` in PROD1 database. 创建操作系统目录`/home/oracle/scripts/cust_files`,并指向PROD1数据库中的目录`dir_dmp`。 Load data into the `TEST_SPEC`, using the script name of `securelob_sp.sql`. 使用脚本名称`securelob_sp.sql`将数据加载到`TEST_SPEC`中。 ```sql -- 创建一个目录以存储文件 host mkdir -p /home/oracle/scripts/cust_files -- 使用host命令在操作系统中创建目录 -- 在Oracle数据库中创建一个目录对象,指向上述路径 create directory dir_dmp as '/home/oracle/scripts/cust_files'; -- 授予公共用户对目录的读、写和执行权限 grant read, write, execute on directory dir_dmp to public; -- 授权公共用户对目录的访问权限 -- 查看 securelob_sp.sql 脚本内容 host cat /home/oracle/scripts/securelob_sp.sql -- 显示脚本文件内容 -- 创建或替换存储过程 sp_imp_blob create or replace procedure sp_imp_blob is a_blob BLOB; -- 定义一个 BLOB 类型的变量 a_bfile BFILE := BFILENAME('DIR_DMP', 'test.f'); -- 定义一个 BFILE 类型的变量,指向目录中的 test.f 文件 begin for i in 1..10000 loop -- 循环 10000 次 -- 插入一条记录到 TEST_SPEC 表中,并返回 DOC 列的空 BLOB 变量 insert into TEST_SPEC values (i, empty_blob()) returning doc into a_blob; dbms_lob.fileopen(a_bfile); -- 打开 BFILE -- 从 BFILE 加载数据到 BLOB 变量中 dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile)); dbms_lob.fileclose(a_bfile); -- 关闭 BFILE commit; -- 提交事务 end loop; end; -- 结束存储过程 / -- 执行存储过程 securelob_sp.sql @/home/oracle/scripts/securelob_sp.sql -- 运行脚本 -- 切换到脚本目录 cd /home/oracle/scripts/ -- 将 test.f 文件复制到 cust_files 目录中 cp test.f cust_files -- 复制文件 -- 执行存储过程 sp_imp_blob exec sp_imp_blob; -- 执行存储过程以导入 BLOB 数据 -- 查询 TEST_SPEC 表中的记录数量 select count(*) from test_spec; -- 统计 TEST_SPEC 表中的记录数 ``` 2.2. Create a new tablespace in the PROD1 database and create a new table in the HR schema with the following specifications: 在PROD1数据库中创建一个新表空间,并在HR模式下创建一个新表,具有以下规格: 2.2.1. Tablespace `LOB_DATA` with a 16KB chunk size, initial and next extents each with a size of 2MB. 表空间`LOB_DATA`,块大小为16KB,初始和下一个范围的大小均为2MB。 ``` create tablespace lob_data datafile '/u01/app/oracle/oradata/PROD1/lob_data01.dbf' size 50M autoextend on maxsize 2G extent management local uniform size 2M blocksize 16k; ``` 2.2.2. Table name `MAGAZINE_ARTICLES`, Tablespace `USERS`, Column names: 表名`MAGAZINE_ARTICLES`,表空间`USERS`,列名: - AUTHOR VARCHAR2(30) - ARTICLE_NAME VARCHAR2(50) - ARTICLE_DATE DATE - ARTICLE_DATA CLOB The data in this table is not accessed frequently. 此表中的数据不经常访问。 The blocks retrieved for this table should be placed at the least recently used end of the LRU list in the buffer cache. 此表检索的块应放置在缓冲缓存的LRU列表的最不常用端。 Disable storage in row. 禁用行内存储。 ``` conn hr/hr -- 创建一个名为 magazine_articles 的表 CREATE TABLE magazine_articles ( author VARCHAR2(30), article_name VARCHAR2(50), article_date DATE, article_data CLOB ) TABLESPACE users -- 指定表存储在 users 表空间中 LOB(article_data) STORE AS ( -- 指定 article_data 列的存储方式为 LOB TABLESPACE lob_data -- 指定 LOB 数据存储在 lob_data 表空间中 CHUNK 16K -- 每个 LOB 的块大小为 16KB STORAGE ( -- 配置 LOB 的存储选项 INITIAL 2M -- 初始分配的存储空间为 2MB NEXT 2M -- 下一个分配的存储空间为 2MB ) NOCACHE -- 不使用缓存,直接从磁盘读取数据 DISABLE STORAGE IN ROW -- 不将 LOB 数据存储在行中,而是存储在独立的 LOB 区域 ); ``` 2.2.3. Use `datapump impdp` to populate the `HR.MAGAZINE_ARTICLES` table with data from the `expmaga.dmp` file located in the `/home/oracle/scripts` folder. 使用`datapump impdp`从`/home/oracle/scripts`文件夹中的`expmaga.dmp`文件填充`HR.MAGAZINE_ARTICLES`表。 ``` pwd /home/oracle/scripts export ORACLE_SID=PROD1 impdp hr/hr directory=tune_results dumpfile=expmaga.dmp TABLE_EXISTS_ACTION=APPEND select count(*) from magazine_articles; ``` ### Section 3: Create and Manage Encrypted Tablespace ### 第三部分:创建和管理加密表空间 3.1. Log in as SYS to the PROD3 database. Run the `/home/oracle/scripts/sec_tbs.sql` script. 以SYS身份登录到PROD3数据库。运行脚本`/home/oracle/scripts/sec_tbs.sql`。 ```sql sqlplus sys/oracle@prod3 as sysdba host cat /home/oracle/scripts/sec_tbs.sql @/home/oracle/scripts/sec_tbs.sql create temporary tablespace temp tempfile '/u01/app/oracle/oradata/PROD3/temp_new.dbf' size 100m autoextend on; ``` 3.2. Create an encrypted tablespace with the following specifications: 创建一个加密表空间,具有以下规格: - Tablespace name: `ENCT_DATA`, File size: 50 MB 表空间名:`ENCT_DATA`,文件大小:50MB ``` # 设置环境变量 ORACLE_SID,指定当前数据库实例名为 PROD3 export ORACLE_SID=PROD3 # 以 SYSDBA 身份连接到 SQL*Plus sqlplus / as sysdba # 查询当前数据库加密钱包的状态 select * from v$encryption_wallet; # 创建一个目录,用于存放加密钱包 mkdir -p /u01/app/oracle/admin/PROD3/wallet # 设置数据库的加密密钥,使用指定的密码 alter system set encryption key identified by oracle; # 再次查询当前数据库加密钱包的状态,确认密钥设置成功 select * from v$encryption_wallet; # 创建一个名为 ENCT_DATA 的表空间,指定数据文件的路径、大小和加密选项 create tablespace ENCT_DATA datafile '/u01/app/oracle/oradata/PROD3/sec01.dbf' size 50M encryption default storage(encrypt); # 查询表空间的名称和加密状态,以确认 ENCT_DATA 表空间是否已加密 select tablespace_name, encrypted from dba_tablespaces where tablespace_name ='ENCT_DATA'; ``` ### Section 4: Set Up Fine-Grained Auditing ### 第四部分:设置细粒度审计 4.1. Set up fine-grained auditing (FGA) on the `SALARY` and `COMMISSION_PCT` columns of the `EMPLOYEES` table in the HR schema of the PROD1 database. 在PROD1数据库HR模式的`EMPLOYEES`表的`SALARY`和`COMMISSION_PCT`列上设置细粒度审计(FGA)。 An audit record should be created if either of these columns is selected as part of the output of a query or is used in the WHERE condition of a SELECT statement and their values are not null. 如果选择这些列作为查询输出的一部分,或者在SELECT语句的WHERE条件中使用,并且其值不为null,则应创建审计记录。 ``` --第一张方法 -- 使用 DBMS_FGA 包添加一个细粒度审计策略 EXEC DBMS_FGA.ADD_POLICY( 'HR', -- 审计策略所属的模式(schema),这里是 HR 'EMPLOYEES', -- 要应用审计策略的表名,这里是 EMPLOYEES 表 'EMP_POC', -- 审计策略的名称,这里命名为 EMP_POC 'salary is not null and commission_pct is not null', -- 审计条件,只有当 salary 和 commission_pct 都不为 null 时才审计 'salary, commission_pct', -- 要审计的列,这里是 salary 和 commission_pct 列 'select' -- 指定审计的操作类型,这里是 SELECT 操作 ); -- 使用 DBMS_FGA 包删除之前添加的审计策略 -- 该命令会删除名为 EMP_POC 的审计策略,适用于 HR 模式下的 EMPLOYEES 表 EXEC DBMS_FGA.DROP_POLICY('HR', 'EMPLOYEES', 'EMP_POC'); --第二种方法 vi fga.sql begin DBMS_FGA.ADD_POLICY ( object_schema => 'HR', object_name => 'EMPLOYEES', policy_name => 'mypolicy1', audit_condition => 'SALARY is not null and COMMISSION_PCT is not null', audit_column => 'SALARY,COMMISSION_PCT', handler_schema => NULL, handler_module => NULL, enable => TRUE, statement_types => 'select', audit_trail => DBMS_FGA.DB + DBMS_FGA.EXTENDED, audit_column_opts => DBMS_FGA.ANY_COLUMNS); end; / @fga.sql select policy_name,object_name from dba_audit_policies where policy_name = 'MYPOLICY1'; ``` 4.2. Validate that the FGA is taking place by executing statements that result in auditing records being created and by executing statements where no auditing records will be generated. 通过执行生成审计记录的语句和执行不会生成审计记录的语句来验证FGA的发生。 Do not delete your audit records. 请勿删除您的审计记录。 ``` -- 查询 employees 表中 salary 列为 NULL 的所有记录 select * from employees where salary is null; -- 查询 employees 表中 salary 和 COMMISSION_PCT 列均不为 NULL 的所有记录 select * from employees where SALARY is not null and COMMISSION_PCT is not null; -- 查询 DBA_FGA_AUDIT_TRAIL 视图中的 SQL 文本,查看细粒度审计记录 select SQL_TEXT from dba_fga_audit_trail; -- 查询 fga_log$ 表中的 LSQLTEXT 列,查看细粒度审计的 SQL 文本 select LSQLTEXT from fga_log$; ``` ### Section 5: Configure the Database to Retrieve All Previous Versions of the Table Rows ### 第五部分:配置数据库以检索所有表行的先前版本 5.1. Perform the following tasks. 执行以下任务。 5.1.1. Create a table named `ORIGINAL_SALARY` in the HR schema in the PROD1 database. 在PROD1数据库的HR模式中创建一个名为`ORIGINAL_SALARY`的表。 `ORIGINAL_SALARY` includes the `EMPLOYEE_ID`, `COMMISSION_PCT`, and `SALARY` of all records in the `HR.EMPLOYEES` table. `ORIGINAL_SALARY`包含`HR.EMPLOYEES`表中所有记录的`EMPLOYEE_ID`、`COMMISSION_PCT`和`SALARY`。 ``` create table original_salary as select employee_id,commission_pct,salary from employees; Table created. HR@PROD1> sele select current_scn,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from v$database; ``` 5.1.2. Delete all employees in the `HR.ORIGINAL_SALARY` table whose `HIRE_DATE` is before 2002. 删除`HR.ORIGINAL_SALARY`表中`HIRE_DATE`在2002年之前的所有员工。 Note the date and time, and then commit the changes. 记录日期和时间,然后提交更改。 Create an `HR.SALARY_VIEW` view that will show all the original rows before the deletion. 创建一个`HR.SALARY_VIEW`视图,将显示删除前的所有原始行。 ``` delete from original_salary where employee_id in commit; create view salary_view as (select * from original_salary as of scn 1443660); select count(*) from salary_view; create view salary_view as (select * from original_salary as of timestamp to_timestamp('2017-12-26 15:17:42','yyyy-mm-dd hh24:mi:ss')) ``` 5.1.3. A table named `DEPARTMENTS_NEW`, owned by HR, was accidentally dropped by a DBA logging in to the wrong database. 一个名为`DEPARTMENTS_NEW`的表,由HR拥有,因DBA登录到错误的数据库而意外删除。 There may be more than one copy of the table that has been dropped. 可能有多个已删除的表副本。 The user wants you to recover the table that has a column named `DEPARTMENT_NAME`. 用户希望您恢复一个名为`DEPARTMENT_NAME`的列的表。 Restore the table and name it `MD_RCV`. 恢复该表并命名为`MD_RCV`。 ``` show recyclebin --闪回删除 flashback table "BIN$YNke6gG6ba/gUwsCAMCaBg==$0" to before drop rename to md_rcv; desc md_rcv alter table MD_RCV rename constraint "BIN$YNke6gG3ba/gUwsCAMCaBg==$0" to md_rcv_con; elect constraint_name,table_name from user_constraints where table_name='MD_RCV'; select constraint_name,table_name from user_constraints where select index_name,table_name from user_indexes where table_name='MD_RCV'; ``` 5.2. Perform the necessary configurations in the PROD1 database so that all previous versions of the rows for the past one year in the `SH.PROMOTIONS` table are retrievable. 在PROD1数据库中执行必要的配置,以便可以检索过去一年内`SH.PROMOTIONS`表中行的所有先前版本。 5.2.1. Create and use the following tablespace and user to perform necessary configurations: 创建并使用以下表空间和用户执行必要的配置: - Tablespace named `FRATBS` with a data file of 50 MB 表空间名为`FRATBS`,数据文件为50MB - User named `FR_ADMIN` 用户名为`FR_ADMIN` ``` -- 创建一个名为 fratbs 的表空间 CREATE TABLESPACE fratbs DATAFILE '/u01/app/oracle/oradata/PROD1/fratbs01.dbf' -- 指定数据文件的路径 SIZE 50M; -- 设置数据文件的初始大小为 50MB -- 创建一个名为 fr_admin 的用户,设置密码和默认表空间 CREATE USER fr_admin IDENTIFIED BY fr_admin DEFAULT TABLESPACE fratbs; -- 将默认表空间设置为 fratbs -- 授予用户 fr_admin 连接和资源管理的权限 GRANT connect, resource TO fr_admin; -- 查询系统权限,查看包含 FLASHBACK 的权限 SELECT privilege FROM dba_sys_privs WHERE privilege LIKE '%FLASHBACK%'; -- 使用 fr_admin 用户连接到数据库 CONN fr_admin/fr_admin; -- 创建一个名为 fra1 的闪回归档,指定表空间和保留时间 CREATE FLASHBACK ARCHIVE fra1 TABLESPACE fratbs -- 指定存储闪回归档的表空间 RETENTION 1 YEAR; -- 设置闪回归档保留期限为 1 年 ``` 5.2.2. Previous versions of the rows in the `SH.PROMOTIONS` table should be retrievable from an archive `FRA1`, and includes data that will be retained for one year. `SH.PROMOTIONS`表中行的先前版本应可从归档`FRA1`中检索,并包括将保留一年的数据。 You should be able to perform DDL operations on the base table, `SH.PROMOTIONS`. 您应该能够在基本表`SH.PROMOTIONS`上执行DDL操作。 Run the `s4_1.sql` script located in the `/home/oracle/scripts` directory. 运行位于`/home/oracle/scripts`目录中的`s4_1.sql`脚本。 ``` create flashback archive fra1 tablespace fratbs retention 1 year; select owner_name,flashback_archive_name,retention_in_days from dba_flashback_archive; grant flashback archive on fra1 to sh; conn sh/sh alter table promotions flashback archive fra1; select * from dba_flashback_archive_tables; 注:以上是权限最小化操作,也可以用 sys操作 如:conn / as sysdba alter table sh.promotions flashback archive fra1; @/home/oracle/scripts/s4_1.sql 完成插入之后,验证结果: select count(*) from NEW_ORDER_ITEMS; select count(*) from NEW_ORDER_ITEMS; ``` ### Section 6: Create Partitioned Tables ### 第六部分:创建分区表 6.1. Create a partitioned table called `NEW_ORDER_ITEMS` in the PROD1 database using the range-partitioned `NEW_ORDERS` table. 在PROD1数据库中创建一个名为`NEW_ORDER_ITEMS`的分区表,使用范围分区的`NEW_ORDERS`表。 The `NEW_ORDER_ITEMS` partitioned table should avoid storing unnecessary columns. `NEW_ORDER_ITEMS`分区表应避免存储不必要的列。 ```sql --查看 new_orders表分区对应表空间 select TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME from user_tab_partitions where table_name='NEW_ORDERS'; --如果分区不在对应表空间,可以使用如下语句移动表分区 alter table NEW_ORDERS move partition Q1_2005 tablespace tbs 1 update global indexes; alter table NEW_ORDERS move partition Q2_2005 tablespace tbs1 update global indexes; alter table NEW_ORDERS move partition Q3_2005 tablespace tbs2 update global indexes; alter table NEW_ORDERS move partition Q4_2005 tablespace tbs2 update global indexes; --查询 new_orders 表中主键列 select constraint_name,constraint_type from user_constraints where table_name='NEW_ORDERS'; select constraint_name,column_name from user_cons_columns where table_name='NEW_ORDERS'; ``` 6.1.1. Use the following column specifications for creating the `NEW_ORDER_ITEMS` table: 使用以下列规格创建`NEW_ORDER_ITEMS`表: - ORDER_ID NUMBER(12) NOT NULL - LINE_ITEM_ID NUMBER(3) NOT NULL - PRODUCT_ID NUMBER NOT NULL - QUANTITY NUMBER NOT NULL - SALES_AMOUNT NUMBER NOT NULL ``` CREATE TABLE new_order_items ( ORDER_ID NUMBER(12) NOT NULL, LINE_ITEM_ID NUMBER(3) NOT NULL, PRODUCT_ID NUMBER NOT NULL, QUANTITY NUMBER NOT NULL, SALES_AMOUNT NUMBER NOT NULL, CONSTRAINT order_items_fk FOREIGN KEY(order_id) REFERENCES new_orders(order_id) ) PARTITION BY REFERENCE(order_items_fk); --查看创建结果 select table_name,partition_name,tablespace_name from user_tab_partitions where table_name = 'NEW_ORDER_ITEMS'; ``` 6.1.2. Populate the `NEW_ORDERS` and `NEW_ORDER_ITEMS` tables by executing SQL script located in the `/home/oracle/scripts` directory. 通过执行位于`/home/oracle/scripts`目录中的SQL脚本填充`NEW_ORDERS`和`NEW_ORDER_ITEMS`表。 AS FOLLOWS: 如下所示: ```sql --如果空间小添加空间、开启自动扩展 select file_name,tablespace_name from dba_data_files where tablespace_name like 'TBS%'; alter database datafile '/u01/app/oracle/oradata/PROD1/tbs1_01.dbf' autoextend on maxsize 2G; alter database datafile '/u01/app/oracle/oradata/PROD1/tbs2_01.dbf' autoextend on maxsize 2G; insert into new_orders values(101,to_date('2005-02-03','yyyy-mm-dd'),'x1',1001,1,20000,88001,88002); insert into new_orders values(102,to_date('2005-05-15','yyyy-mm-dd'),'x1',1002,1,30000,88002,88002); insert into new_orders values(103,to_date('2005-09-22','yyyy-mm-dd'),'x1',1003,1,40000,88003,88002); insert into new_orders values(104,to_date('2005-12-30','yyyy-mm-dd'),'x1',1004,1,10000,88004,88002); insert into new_order_items values(101,801,200001,200,100); insert into new_order_items values(102,802,200002,300,100); insert into new_order_items values(103,803,200003,400,100); insert into new_order_items values(104,804,200004,100,100); commit; --验证 select count(*) from new_orders; select count(*) from NEW_ORDER_ITEMS; ``` 6.2. Create a partitioned table that automatically stores rows for nonexistent partitions. 创建一个自动存储不存在分区的行的分区表。 ``` 1)创建间隔分区表时,题目中的表名,分区名,字段类型及名称及从第几年开始一定要仔细查看,建议直接从题目中复制字段定义。 2)题目未明确说明表空间,但表空间 sales_tbs1,sales_tbs2,sales_tbs3,sales_tbs4 已经存 在了,使用这几个表空间。注意 resize,autoextend on 调整表空间数据文件。 ``` 6.2.1. Log in as the SH user to the PROD1 database, and create a `newsales2006_history` table. 以SH用户身份登录到PROD1数据库,并创建`newsales2006_history`表。 The table should have the following columns: 该表应具有以下列: - PROD_ID NUMBER NOT NULL - CUST_ID NUMBER NOT NULL - TIME_ID DATE NOT NULL - CHANNEL_ID VARCHAR2(10) NOT NULL - PROMO_ID NUMBER NOT NULL - QUANTITY_SOLD NUMBER(10,2) NOT NULL - AMOUNT_SOLD NUMBER(10,2) NOT NULL 6.2.2. Partitions should be based on the `TIME_ID` column. 分区应基于`TIME_ID`列。 Data for the years 2001, 2002, 2003, and 2004 should be stored in separate partitions having partition names `SAL1`, `SAL2`, `SAL3`, and `SAL4`, respectively, and data after 2004 is stored in a separate partition for each month. 2001、2002、2003和2004年的数据应存储在分别名为`SAL1`、`SAL2`、`SAL3`和`SAL4`的单独分区中,并且2004年之后的数据在每个月的单独分区中存储。 Use the script in the `/home/oracle/scripts` directory to populate the table. 使用`/home/oracle/scripts`目录中的脚本填充该表。 AS FOLLOWS: 如下所示: ```sql insert into sh.newsales2006_history values(908001,101,to_date('2002-8-10','yyyy-mm-dd'),'a',88001,100,200); insert into sh.newsales2006_history values(908002,102,to_date('2003-7-10','yyyy-mm-dd'),'a',88002,100,800); insert into sh.newsales2006_history values(908003,103,to_date('2004-5-30','yyyy-mm-dd'),'a',88003,100,700); insert into sh.newsales2006_history values(908004,104,to_date('2005-12-10','yyyy-mm-dd'),'a',88004,100,600); insert into sh.newsales2006_history values(908005,105,to_date('2007-11-14','yyyy-mm-dd'),'a',88005,100,500); commit; ``` ``` --interval分区表 CREATE TABLE newsales2006_history ( PROD_ID NUMBER NOT NULL, CUST_ID NUMBER NOT NULL, TIME_ID DATE NOT NULL, CHANNEL_ID VARCHAR2(10) NOT NULL, PROMO_ID NUMBER NOT NULL, QUANTITY_SOLD NUMBER(10, 2) NOT NULL, AMOUNT_SOLD NUMBER(10, 2) NOT NULL ) PARTITION BY RANGE (time_id) INTERVAL(NUMTOYMINTERVAL(1, 'MONTH')) store in (SALES_TBS1, SALES_TBS2, SALES_TBS3, SALES_TBS4) ( PARTITION sal1 VALUES LESS THAN (TO_DATE('1-1-2002', 'DD-MM-YYYY')) tablespace SALES_TBS1, PARTITION sal2 VALUES LESS THAN (TO_DATE('1-1-2003', 'DD-MM-YYYY')) tablespace SALES_TBS2, PARTITION sal3 VALUES LESS THAN (TO_DATE('1-1-2004', 'DD-MM-YYYY')) tablespace SALES_TBS3, PARTITION sal4 VALUES LESS THAN (TO_DATE('1-1-2005', 'DD-MM-YYYY')) tablespace SALES_TBS4 ); ``` ``` select table_name,partition_name from user_tab_partitions where table_name like 'NEWSALES%'; select count(*) from NEWSALES2006_HISTORY; select * from newsales2006_history partition(sal1); select * from newsales2006_history partition(sal2); ```
上一篇:
S3
下一篇:
S5
0
赞
12 人读过
新浪微博
微信
腾讯微博
QQ空间
人人网