您好,登錄后才能下訂單哦!
這篇文章主要介紹“Oracle12C新特性有哪些”,在日常操作中,相信很多人在Oracle12C新特性有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Oracle12C新特性有哪些”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
1、只讀分區或子分區
在Oracle12.2數據庫中可以將表,分區和子分區設置為只讀狀態,以保護數據免受任何用戶或觸發器的無意DML操作。
只讀子句的值可以是READ ONLY或READ WRITE。READ WRITE是默認值。除非為分區或子分區顯式設置了只讀子句,否則只讀子句的更高級別設置將應用于分區和子分區!
例子:創建具有只讀和讀寫分區的表:orders_read_write_only
以下是創建具有只讀和讀寫狀態的復合范圍列表分區表的示例。將orders_read_write_only被明確指定為READ WRITE,所以表的默認屬性是讀寫。partition的默認屬性order_p1被指定為只讀,因此子分區ord_p1_northwest和order_p1_southwest從分區繼承只讀狀態order_p1。子分區ord_p2_southwest和order_p3_northwest顯式指定為只讀,覆蓋默認讀寫狀態。
CREATE TABLE orders_read_write_only ( order_id NUMBER (12), order_date DATE CONSTRAINT order_date_nn NOT NULL, state VARCHAR2(2) ) READ WRITE PARTITION BY RANGE (order_date) SUBPARTITION BY LIST (state) ( PARTITION order_p1 VALUES LESS THAN (TO_DATE ('01-DEC-2015','DD-MON-YYYY')) READ ONLY ( SUBPARTITION order_p1_northwest VALUES ('OR', 'WA'), SUBPARTITION order_p1_southwest VALUES ('AZ', 'UT', 'NM')), PARTITION order_p2 VALUES LESS THAN (TO_DATE ('01-MAR-2016','DD-MON-YYYY')) ( SUBPARTITION order_p2_northwest VALUES ('OR', 'WA'), SUBPARTITION order_p2_southwest VALUES ('AZ', 'UT', 'NM') READ ONLY), PARTITION order_p3 VALUES LESS THAN (TO_DATE ('01-JUL-2016','DD-MON-YYYY')) (SUBPARTITION order_p3_northwest VALUES ('OR', 'WA') READ ONLY, SUBPARTITION order_p3_southwest VALUES ('AZ', 'UT', 'NM')) );
--檢查分區和子分區的狀態:
SQL> SELECT PARTITION_NAME, READ_ONLY FROM USER_TAB_PARTITIONS WHERE TABLE_NAME ='ORDERS_READ_WRITE_ONLY'; PARTITION_NAME READ ------------------------- ---- ORDER_P1 YES ---只讀狀態 ORDER_P2 NONE ORDER_P3 NONE SQL> set linesize 300 SQL> col PARTITION_NAME for a25 SQL> col SUBPARTITION_NAME for a25 SQL> SELECT PARTITION_NAME, SUBPARTITION_NAME, READ_ONLY FROM USER_TAB_SUBPARTITIONS WHERE TABLE_NAME ='ORDERS_READ_WRITE_ONLY'; PARTITION_NAME SUBPARTITION_NAME REA ------------------------- ------------------------- --- ORDER_P1 ORDER_P1_NORTHWEST YES ORDER_P1 ORDER_P1_SOUTHWEST YES ORDER_P2 ORDER_P2_NORTHWEST NO ORDER_P2 ORDER_P2_SOUTHWEST YES ORDER_P3 ORDER_P3_NORTHWEST YES ORDER_P3 ORDER_P3_SOUTHWEST NO 6 rows selected.
(從上面可以看出,如果單獨設置子分區為只讀狀態 會覆蓋分區的讀寫屬性,也就是說對一個分區的子分區進行設置只讀狀態 不會影響這個分區下的其他子分區的屬性!)
--:分區的屬性可以通過modify語句進行在線修改。
SQL> alter table ORDERS_READ_WRITE_ONLY modify partition ORDER_P1 read write;
################################################################
2、創建 外部表分區:
在12.2中,Oracle還支持外部表分區,類似如下的語法展示了這一特性的用途,對于一個統一的外部表,可以通過分區指向不同的外部文件,不同文件可以用于存儲已經分類的數據,從而更加靈活的使用外部表:
例子:
SQL> Create directory load_d1 as '/home/oracle'; CREATE TABLE sales (loc_id number, prod_id number, cust_id number, amount_sold number, quantity_sold number) ORGANIZATION EXTERNAL (TYPE oracle_loader DEFAULT DIRECTORY load_d1 ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII NOBADFILE LOGFILE log_dir:'sales.log' FIELDS TERMINATED BY "," ) ) REJECT LIMIT UNLIMITED PARTITION BY RANGE (loc_id) (PARTITION p1 VALUES LESS THAN (1000) LOCATION ('california.txt'), PARTITION p2 VALUES LESS THAN (2000) DEFAULT DIRECTORY load_d2 LOCATION ('washington.txt'), PARTITION p3 VALUES LESS THAN (3000));
###########################################################
3、列表分區:
創建列表分區的語義與創建范圍分區的語義非常相似。從Oracle12.2開始可以創建多列列表分區。
例子:創建列表分區
CREATE TABLE q1_sales_by_region (deptno number, deptname varchar2(20), quarterly_sales number(10, 2), state varchar2(2)) PARTITION BY LIST (state) (PARTITION q1_northwest VALUES ('OR', 'WA'), PARTITION q1_southwest VALUES ('AZ', 'UT', 'NM'), PARTITION q1_northeast VALUES ('NY', 'VM', 'NJ'), PARTITION q1_southeast VALUES ('FL', 'GA'), PARTITION q1_northcentral VALUES ('SD', 'WI'), PARTITION q1_southcentral VALUES ('OK', 'TX'));
3.1、、使用默認分區創建列表分區:(指定默認分區就是將不符合的行都插入到默認分區中)
與范圍分區不同,使用列表分區,分區之間沒有明顯的順序感。
您還可以指定一個默認分區,將未映射到任何其他分區的行映射到該分區。如果在前面的示例中指定了默認分區,則狀態CA將映射到該分區。
例子:使用默認分區創建列表分區表
CREATE TABLE sales_by_region (item# INTEGER, qty INTEGER, store_name VARCHAR(30), state_code VARCHAR(2),sale_date DATE) STORAGE(INITIAL 10K NEXT 20K) TABLESPACE tbs5 PARTITION BY LIST (state_code) (PARTITION region_east VALUES ('MA','NY','CT','NH','ME','MD','VA','PA','NJ') STORAGE (INITIAL 8M) TABLESPACE tbs8, PARTITION region_west VALUES ('CA','AZ','NM','OR','WA','UT','NV','CO') NOLOGGING, PARTITION region_south VALUES ('TX','KY','TN','LA','MS','AR','AL','GA'), PARTITION region_central VALUES ('OH','ND','SD','MO','IL','MI','IA'), PARTITION region_null VALUES (NULL), PARTITION region_unknown VALUES (DEFAULT));
3.2、創建自動列表分區:
自動列表分區方法允許按需創建列表分區。
自動列表分區表類似于常規列表分區表,但該分區表更易于管理。您可以僅使用已知的分區鍵值創建自動列表分區表。當數據加載到表中時,如果加載的分區鍵值與任何現有分區不對應,則數據庫會自動創建新分區。由于分區是按需自動創建的,因此自動列表分區方法在概念上與現有的間隔分區方法類似。
注意:
①:除非您可以調整數據,否則對值非常頻繁更改的數據類型的自動列表分區不太適合此方法。
②:自動列表分區表在創建時必須至少有一個分區。由于為新的和未知的分區鍵值自動創建了新分區,因此自動列表分區不能具有DEFAULT分區。
例子:
CREATE TABLE sales_auto_list ( salesman_id NUMBER(5), salesman_name VARCHAR2(30), sales_state VARCHAR2(20), sales_amount NUMBER(10), sales_date DATE) PARTITION BY LIST (sales_state) AUTOMATIC (PARTITION P_CAL VALUES ('CALIFORNIA') );
--查看列表分區是否為自動列表分區
SQL> col TABLE_NAME for a20 SQL> col owner for a10 SQL> set linesize 300 SQL> select OWNER,TABLE_NAME,PARTITIONING_TYPE,AUTOLIST from dba_PART_TABLES where table_name=upper('sales_auto_list'); OWNER TABLE_NAME PARTITION AUT ---------- -------------------- --------- --- SYS SALES_AUTO_LIST LIST YES
3.3、創建多列列表分區:
與單列列表分區類似,各個分區可以包含包含值列表的集合。
語法:PARTITION BY LIST (column1,column2)
例子:創建多列列表分區
CREATE TABLE dba_by_db_in_yhem (dbalic NUMBER, username VARCHAR2(20), dbcat VARCHAR2(4), region VARCHAR2(10) ) PARTITION BY LIST (dbcat, region) ( PARTITION north_part VALUES (('ORCL','BEIJING'), ('ORCL','TIANJIN')), PARTITION south_part VALUES (('DB2','SHENZHEN'), ('DB2','GUANGZHOU')), PARTITION west_part VALUES (('SQL','CHENGDU'),('ORCL','CHENGDU'),('DB2','KUNMING')), PARTITION east_part VALUES ('ORCL','SHANGHAI'), PARTITION rest VALUES (DEFAULT) ); insert into dba_by_db_in_yhem values(1,'EYGLE','ORCL','BEIJING'); insert into dba_by_db_in_yhem values(2,'KAMUS','ORCL','BEIJING'); insert into dba_by_db_in_yhem values(3,'LAOXIONG','SQL','CHENGDU'); insert into dba_by_db_in_yhem values(4,'ORA-600','DB2','GUANGZHOU'); insert into dba_by_db_in_yhem values(5,'YANGTINGKUN','ALL','BEIJING'); SQL> select * from dba_by_db_in_yhem partition (north_part); DBALIC USERNAME DBCA REGION ---------- -------------------- ---- ---------- 1 EYGLE ORCL BEIJING 2 KAMUS ORCL BEIJING SQL> select * from dba_by_db_in_yhem partition (south_part); DBALIC USERNAME DBCA REGION ---------- -------------------- ---- ---------- 4 ORA-600 DB2 GUANGZHOU
####################################################
指定秘鑰列的分區:
對于范圍分區和散列分區表,最多可以指定16個分區鍵列。
1、按日期創建多列范圍分區表
CREATE TABLE sales_demo ( year NUMBER, month NUMBER, day NUMBER, amount_sold NUMBER) PARTITION BY RANGE (year,month) (PARTITION before2001 VALUES LESS THAN (2001,1), PARTITION q1_2001 VALUES LESS THAN (2001,4), PARTITION q2_2001 VALUES LESS THAN (2001,7), PARTITION q3_2001 VALUES LESS THAN (2001,10), PARTITION q4_2001 VALUES LESS THAN (2002,1), PARTITION future VALUES LESS THAN (MAXVALUE,0)); INSERT INTO sales_demo VALUES(2000,12,12, 1000); INSERT INTO sales_demo VALUES(2001,3,17, 2000); INSERT INTO sales_demo VALUES(2001,11,1, 5000); INSERT INTO sales_demo VALUES(2002,1,1, 4000);
2、創建多列范圍分區表(強制實施相等的分區)
CREATE TABLE supplier_parts ( supplier_id NUMBER, partnum NUMBER, price NUMBER) PARTITION BY RANGE (supplier_id, partnum) (PARTITION p1 VALUES LESS THAN (10,100), PARTITION p2 VALUES LESS THAN (10,200), PARTITION p3 VALUES LESS THAN (MAXVALUE,MAXVALUE)); INSERT INTO supplier_parts VALUES(5,5,1000); INSERT INTO supplier_parts VALUES(5,150,1000); INSERT INTO supplier_parts VALUES(10,100,1000); --查看各分區的值: SQL> SELECT * FROM supplier_parts PARTITION (p1); SUPPLIER_ID PARTNUM PRICE ----------- ---------- ---------- 5 5 1000 5 150 1000 SQL> SELECT * FROM supplier_parts PARTITION (p2); SUPPLIER_ID PARTNUM PRICE ----------- ---------- ---------- 10 100 1000
到此,關于“Oracle12C新特性有哪些”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。