|
Skillset 3:
Section 5:
5.2 Ensure that all the statements execute in parallel. If a statement cannot execute in parallel, it should not execute at all.- create or replace trigger trg1
- after logon on database
- declare
- pragma AUTONOMOUS_TRANSACTION;
- begin
- execute immediate 'alter session force parallel dml parallel 8';
- end;
复制代码- SQL> alter system set db_securefile=PERMITTED;
- System altered.
- SQL> create table oe.CUSTOMER_PROFILES(CUST_ID NUMBER,
- 2 FIRST_NAME VARCHAR2(20),
- 3 LAST_NAME VARCHAR2(30),
- 4 PROFILE_INFO BLOB)
- 5 lob (profile_info) store as securefile
- 6 (
- 7 disable storage in row
- 8 deduplicate
- 9 compress high
- 10 tablespace sf_data)
- 11 tablespace sf_data;
- Table created.
- SQL>
复制代码- select table_name, partition_name, high_value
- from user_tab_partitions
- where table_name in ('NEW_ORDERS','NEW_ORDER_ITEMS')
- order by partition_position, table_name;
复制代码 先用以下语句把NEW_ORDERS表建在SH下面:
- select dbms_metadata.get_ddl('TABLE','ORDERS','OE') from dual;
复制代码- grant select on hr.employees to sh;
-
- grant references on hr.employees to sh;
复制代码
- CREATE TABLE SH.NEW_ORDERS
- ( "ORDER_ID" NUMBER(12,0),
- "ORDER_DATE" date CONSTRAINT "ORDER_DATE_NN" NOT NULL ENABLE,
- "ORDER_MODE" VARCHAR2(8),
- "CUSTOMER_ID" NUMBER(6,0) CONSTRAINT "ORDER_CUSTOMER_ID_NN" NOT NULL ENABLE,
- "ORDER_STATUS" NUMBER(2,0),
- "ORDER_TOTAL" NUMBER(8,2),
- "SALES_REP_ID" NUMBER(6,0),
- "PROMOTION_ID" NUMBER(6,0),
- CONSTRAINT "ORDER_MODE_LOV" CHECK (order_mode in ('direct','online')) ENABLE,
- CONSTRAINT "ORDER_TOTAL_MIN" CHECK (order_total >= 0) ENABLE,
- CONSTRAINT "ORDER_PK" PRIMARY KEY ("ORDER_ID")
- USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS
- STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
- PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
- TABLESPACE "EXAMPLE" ENABLE,
- CONSTRAINT "ORDERS_CUSTOMER_ID_FK" FOREIGN KEY ("CUSTOMER_ID")
- REFERENCES "SH"."CUSTOMERS" ("CUST_ID") ON DELETE SET NULL ENABLE,
- CONSTRAINT "ORDERS_SALES_REP_FK" FOREIGN KEY ("SALES_REP_ID")
- REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ON DELETE SET NULL ENABLE
- )
- partition by range (ORDER_DATE)
- ( partition part1 values less than (to_date('01-JAN-1999','dd-MON-yyyy')) tablespace part_tbs1,
- partition part2 values less than (maxvalue) tablespace part_tbs2) ;
复制代码- create table sh.NEW_ORDER_ITEMS (
- ORDER_ID NUMBER(12) NOT NULL,
- PRODUCT_ID NUMBER NOT NULL,
- QUANTITY NUMBER NOT NULL,
- SALES_AMOUNT NUMBER NOT NULL,
- constraint fk_NEW_ORDER_ITEMS foreign key(ORDER_ID) references sh.NEW_ORDERs)
- partition by reference (fk_NEW_ORDER_ITEMS ) ;
复制代码
验证:
- select table_name, partition_name, high_value
- from dba_tab_partitions tp
- where tp.table_owner ='SH' and table_name in ('NEW_ORDERS','NEW_ORDER_ITEMS')
- order by partition_position, table_name;
复制代码 | TABLE_NAME | PARTITION_NAME | HIGH_VALUE | 1 | NEW_ORDERS | PART1 | <Long> | 2 | NEW_ORDER_ITEMS | PART1 | <Long> | 3 | NEW_ORDERS | PART2 | <Long> | 4 | NEW_ORDER_ITEMS | PART2 | <Long> |
- insert into sh.new_orders select * from oe.orders;
复制代码- insert into sh.new_order_items select ORDER_ID, PRODUCT_ID,QUANTITY,unit_price*QUANTITY
- from oe.order_items;
复制代码
|
|