Oracle學(xué)習(xí):分區(qū)表和索引
Jun 07, 2016 pm 04:55 PM什么時候使用Oracle分區(qū): 1、 大數(shù)據(jù)量的表,比如大于2GB。一方面2GB文件對于32位os是一個上限,另外備份時間長。 2、
?? 什么時候使用Oracle分區(qū):
??? 1、 大數(shù)據(jù)量的表,比如大于2GB。一方面2GB文件對于32位os是一個上限,另外備份時間長。
??? 2、 包括歷史數(shù)據(jù)的表,比如最新的數(shù)據(jù)放入到最新的分區(qū)中。典型的例子:歷史表,只有當(dāng)前月份的數(shù)據(jù)可以被修改,而其他月份只能read-only
??? ORACLE只支持以下分區(qū):tables, indexes on tables, materialized views, and indexes on materialized views
??? 分區(qū)對SQL和DML是透明的(應(yīng)用程序不必知道已經(jīng)作了分區(qū)),但是DDL可以對不同的分區(qū)進(jìn)行管理。
??? 不同的分區(qū)之間必須有相同的邏輯屬性,比如共同的表名,列名,數(shù)據(jù)類型,約束;
??? 但是可以有不同的物理屬性,比如pctfree, pctused, and tablespaces.
??? 分區(qū)獨(dú)立性:即使某些分區(qū)不可用,其他分區(qū)仍然可用。
??? 最多可以分成64000個分區(qū),但是具有LONG or LONG RAW列的表不可以,,但是有CLOB or BLOB列的表可以。
??? 可以不用to_date函數(shù),比如:
??? alter session set nls_date_format='mm/dd/yyyy';
??? CREATE TABLE sales_range
??? (salesman_id NUMBER(5),
??? salesman_name VARCHAR2(30),
??? sales_amount NUMBER(10),
??? sales_date DATE)
??? PARTITION BY RANGE(sales_date)
??? (
??? PARTITION sales_jan2000 VALUES LESS THAN('02/01/2000'),
??? PARTITION sales_feb2000 VALUES LESS THAN('03/01/2000'),
??? PARTITION sales_mar2000 VALUES LESS THAN('04/01/2000'),
??? PARTITION sales_apr2000 VALUES LESS THAN('05/01/2000')
??? );
??? Partition Key:最多16個columns,可以是nullable的
??? 非分區(qū)的表可以有分區(qū)或者非分區(qū)的索引;
??? 分區(qū)表可以有分區(qū)或者非分區(qū)的索引;
??? Partitioning 方法:
??? Range Partitioning
??? List Partitioning
??? Hash Partitioning
??? Composite Partitioning
??? Composite Partitioning:組合,以及 range-hash and range-list composite partitioning
??? Range Partitioning:
??? 每個分區(qū)都有VALUES LESS THAN子句,表示這個分區(qū)小于(=)前一個分區(qū)的VALUES LESS THAN值。
??? MAXVALUE定義最高的分區(qū),他表示一個虛擬的無限大的值。這個分區(qū)包括null值。
??? CREATE TABLE sales_range
??? (salesman_id NUMBER(5),
??? salesman_name VARCHAR2(30),
??? sales_amount NUMBER(10),
??? sales_date DATE)
??? PARTITION BY RANGE(sales_date)
??? (
??? PARTITION sales_jan2000 VALUES LESS THAN(TO_DATE('01/02/2000','DD/MM/YYYY')),
??? PARTITION sales_feb2000 VALUES LESS THAN(TO_DATE('01/03/2000','DD/MM/YYYY')),
??? PARTITION sales_mar2000 VALUES LESS THAN(TO_DATE('01/04/2000','DD/MM/YYYY')),
??? PARTITION sales_apr2000 VALUES LESS THAN(TO_DATE('01/05/2000','DD/MM/YYYY')),
??? PARTITION sales_2000 VALUES LESS THAN(MAXVALUE)
??? );
??? 插入數(shù)據(jù):
??? Insert into sales_range values(1,2,3,to_date('21-04-2000','DD-MM-YYYY'));
??? Insert into sales_range values(1,2,3,sysdate);
??? 選擇數(shù)據(jù):
??? select * from sales_range;
??? select * from sales_range partition(sales_apr2000);
??? select * from sales_range partition(sales_mar2000);
??? select * from sales_range partition(sales_2000);
??? 按照多個列分區(qū):
??? CREATE TABLE sales_range1
??? (salesman_id NUMBER(5),
??? salesman_name VARCHAR2(30),
??? sales_amount NUMBER(10),
??? sales_date DATE)
??? PARTITION BY RANGE(sales_date, sales_amount)
??? (
??? PARTITION sales_jan2000 VALUES LESS THAN(TO_DATE('01/02/2000','DD/MM/YYYY'),1000),
??? PARTITION sales_feb2000 VALUES LESS THAN(TO_DATE('01/03/2000','DD/MM/YYYY'),2000),
??? PARTITION sales_mar2000 VALUES LESS THAN(TO_DATE('01/04/2000','DD/MM/YYYY'),3000),
??? PARTITION sales_apr2000 VALUES LESS THAN(TO_DATE('01/05/2000','DD/MM/YYYY'),4000),
??? PARTITION sales_2000 VALUES LESS THAN(MAXVALUE, MAXVALUE)
??? );
??? Insert into sales_range1 values(1,2,500, TO_DATE('21/01/2000','DD/MM/YYYY'));
??? Insert into sales_range1 values(2,3,1500, sysdate);

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main difference between MySQL and Oracle is licenses, features, and advantages. 1. License: MySQL provides a GPL license for free use, and Oracle adopts a proprietary license, which is expensive. 2. Function: MySQL has simple functions and is suitable for web applications and small and medium-sized enterprises. Oracle has powerful functions and is suitable for large-scale data and complex businesses. 3. Advantages: MySQL is open source free, suitable for startups, and Oracle is reliable in performance, suitable for large enterprises.

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

The key to learning Java without taking detours is: 1. Understand core concepts and grammar; 2. Practice more; 3. Understand memory management and garbage collection; 4. Join online communities; 5. Read other people’s code; 6. Understand common libraries and frameworks; 7. Learn to deal with common mistakes; 8. Make a learning plan and proceed step by step. These methods can help you master Java programming efficiently.

In different application scenarios, choosing MongoDB or Oracle depends on specific needs: 1) If you need to process a large amount of unstructured data and do not have high requirements for data consistency, choose MongoDB; 2) If you need strict data consistency and complex queries, choose Oracle.

Learning SQL requires mastering basic knowledge, core queries, complex JOIN operations and performance optimization. 1. Understand basic concepts such as tables, rows, and columns and different SQL dialects. 2. Proficient in using SELECT statements for querying. 3. Master the JOIN operation to obtain data from multiple tables. 4. Optimize query performance, avoid common errors, and use index and EXPLAIN commands.

Learning Java requires learning basic syntax, object-oriented programming, collection frameworks, exception handling, multithreading, I/O streaming, JDBC, network programming, and advanced features such as reflection and annotation. 1. The basic syntax includes variables, data types, operators and control flow statements. 2. Object-oriented programming covers classes, objects, inheritance, polymorphism, encapsulation and abstraction. 3. The collection framework involves ArrayList, LinkedList, HashSet, and HashMap. 4. Exception handling ensures program robustness through try-catch block. 5. Multithreaded programming requires understanding of thread life cycle and synchronization. 6. I/O streams are used for data reading, writing and file operations. 7. JDBC is used to interact with databases. 8. Network programming passes S

Oracle software can improve performance in a variety of ways. 1) Optimize SQL queries and reduce data transmission; 2) Appropriately manage indexes to balance query speed and maintenance costs; 3) Reasonably configure memory, optimize SGA and PGA; 4) Reduce I/O operations and use appropriate storage devices.

To connect Oracle database to Tableau for data visualization, you need to follow the following steps: 1. Configure Oracle database connection in Tableau, use ODBC or JDBC drivers; 2. Explore data and create visualizations, such as bar charts, etc.; 3. Optimize SQL queries and indexes to improve performance; 4. Use Oracle's complex data types and functions to implement through custom SQL queries; 5. Create materialized views to improve query speed; 6. Use Tableau's interactive functions such as dashboard for in-depth analysis.
