您好,登錄后才能下訂單哦!
這篇文章主要介紹“Oracle12C新特性有哪些”,在日常操作中,相信很多人在Oracle12C新特性有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”O(jiān)racle12C新特性有哪些”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
1、只讀分區(qū)或子分區(qū)
在Oracle12.2數(shù)據(jù)庫中可以將表,分區(qū)和子分區(qū)設置為只讀狀態(tài),以保護數(shù)據(jù)免受任何用戶或觸發(fā)器的無意DML操作。
只讀子句的值可以是READ ONLY或READ WRITE。READ WRITE是默認值。除非為分區(qū)或子分區(qū)顯式設置了只讀子句,否則只讀子句的更高級別設置將應用于分區(qū)和子分區(qū)!
例子:創(chuàng)建具有只讀和讀寫分區(qū)的表:orders_read_write_only
以下是創(chuàng)建具有只讀和讀寫狀態(tài)的復合范圍列表分區(qū)表的示例。將orders_read_write_only被明確指定為READ WRITE,所以表的默認屬性是讀寫。partition的默認屬性order_p1被指定為只讀,因此子分區(qū)ord_p1_northwest和order_p1_southwest從分區(qū)繼承只讀狀態(tài)order_p1。子分區(qū)ord_p2_southwest和order_p3_northwest顯式指定為只讀,覆蓋默認讀寫狀態(tài)。
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')) );
--檢查分區(qū)和子分區(qū)的狀態(tài):
SQL> SELECT PARTITION_NAME, READ_ONLY FROM USER_TAB_PARTITIONS WHERE TABLE_NAME ='ORDERS_READ_WRITE_ONLY'; PARTITION_NAME READ ------------------------- ---- ORDER_P1 YES ---只讀狀態(tài) 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.
(從上面可以看出,如果單獨設置子分區(qū)為只讀狀態(tài) 會覆蓋分區(qū)的讀寫屬性,也就是說對一個分區(qū)的子分區(qū)進行設置只讀狀態(tài) 不會影響這個分區(qū)下的其他子分區(qū)的屬性?。?/p>
--:分區(qū)的屬性可以通過modify語句進行在線修改。
SQL> alter table ORDERS_READ_WRITE_ONLY modify partition ORDER_P1 read write;
################################################################
2、創(chuàng)建 外部表分區(qū):
在12.2中,Oracle還支持外部表分區(qū),類似如下的語法展示了這一特性的用途,對于一個統(tǒng)一的外部表,可以通過分區(qū)指向不同的外部文件,不同文件可以用于存儲已經分類的數(shù)據(jù),從而更加靈活的使用外部表:
例子:
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、列表分區(qū):
創(chuàng)建列表分區(qū)的語義與創(chuàng)建范圍分區(qū)的語義非常相似。從Oracle12.2開始可以創(chuàng)建多列列表分區(qū)。
例子:創(chuàng)建列表分區(qū)
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、、使用默認分區(qū)創(chuàng)建列表分區(qū):(指定默認分區(qū)就是將不符合的行都插入到默認分區(qū)中)
與范圍分區(qū)不同,使用列表分區(qū),分區(qū)之間沒有明顯的順序感。
您還可以指定一個默認分區(qū),將未映射到任何其他分區(qū)的行映射到該分區(qū)。如果在前面的示例中指定了默認分區(qū),則狀態(tài)CA將映射到該分區(qū)。
例子:使用默認分區(qū)創(chuàng)建列表分區(qū)表
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、創(chuàng)建自動列表分區(qū):
自動列表分區(qū)方法允許按需創(chuàng)建列表分區(qū)。
自動列表分區(qū)表類似于常規(guī)列表分區(qū)表,但該分區(qū)表更易于管理。您可以僅使用已知的分區(qū)鍵值創(chuàng)建自動列表分區(qū)表。當數(shù)據(jù)加載到表中時,如果加載的分區(qū)鍵值與任何現(xiàn)有分區(qū)不對應,則數(shù)據(jù)庫會自動創(chuàng)建新分區(qū)。由于分區(qū)是按需自動創(chuàng)建的,因此自動列表分區(qū)方法在概念上與現(xiàn)有的間隔分區(qū)方法類似。
注意:
①:除非您可以調整數(shù)據(jù),否則對值非常頻繁更改的數(shù)據(jù)類型的自動列表分區(qū)不太適合此方法。
②:自動列表分區(qū)表在創(chuàng)建時必須至少有一個分區(qū)。由于為新的和未知的分區(qū)鍵值自動創(chuàng)建了新分區(qū),因此自動列表分區(qū)不能具有DEFAULT分區(qū)。
例子:
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') );
--查看列表分區(qū)是否為自動列表分區(qū)
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、創(chuàng)建多列列表分區(qū):
與單列列表分區(qū)類似,各個分區(qū)可以包含包含值列表的集合。
語法:PARTITION BY LIST (column1,column2)
例子:創(chuàng)建多列列表分區(qū)
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
####################################################
指定秘鑰列的分區(qū):
對于范圍分區(qū)和散列分區(qū)表,最多可以指定16個分區(qū)鍵列。
1、按日期創(chuàng)建多列范圍分區(qū)表
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、創(chuàng)建多列范圍分區(qū)表(強制實施相等的分區(qū))
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); --查看各分區(qū)的值: 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新特性有哪些”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。