oracle learning summary --oracle object

1. View:

   concept: 

        A view is a virtual table. The view does not store data values ​​in the database. The database only stores the definition of the view in the data dictionary.

   Advantages :

       Centralize data for users and simplify data query and processing for users.

       The complexity of the database is shielded, and the user does not have to understand the complexity of the database.

  Simplify the management of user rights, and only grant users the right to use views.

       Facilitate data sharing, multiple users do not have to define the required data.

        Data can be reorganized so that it can be linked to other applications.

    grammar:

CREATE [ORREPLACE] VIEW view_name[(column_name1[,column_name2…
AS
select_statement
[WITHCHECKOPTION]
[WITHREADONLY]

Parameter Description:  

   1. CREATE OR Replace: for creating and modifying views

    2. WITH CHECK OPTION: Used to create views that restrict data access

    3.WITH READONLY: used to create read-only views

2. Sequence:

    concept:

Sequence (SEQUENCE) is a sequence number generator that can automatically generate sequence numbers for rows in a table, producing a set of equally spaced values ​​(type numbers). Does not take up disk space, takes up memory.

Its main purpose is to generate a table's primary key value, which can be referenced in an insert statement, as well as to check the current value through a query, or to advance a sequence to the next value.

    grammar:

CREATE SEQUENCE [schema.]sequence_name
[INCREMENT BY n] --step size
[START WITH N] --start value
[MAXVALUE n|NOMAXVALUE] --maximum value needs to be explained
[MINVALUE n|NOMINVALUE]       
[CYCLE n|NOCYCLE] --loop
[CACHE n|NOCACHE] --cache, (concurrency)
[ORDER|NOORDER];

query sequence

--Keywords in sequence: next_val curr_val

select student1_seq.nextval from dual; -- nextval: the value of the next sequence
select student1_seq.currval from dual; --dual test table curravl: the value generated by the current sequence

--Note: You must first nextval before you can get the value through currval

3. Synonyms

concept:

The function of synonym management is provided in Oracle database. A synonym is an alias for a database schema object and is often used to simplify and secure object access. When a synonym is used, Oracle Database translates it into the name of the corresponding schema object. Similar to the view, the synonym does not occupy the actual storage space, only the definition of the synonym is saved in the data dictionary. Most of the database objects in the Oracle database, such as tables, views, synonyms, sequences, stored procedures, packages, etc., database administrators can define synonyms for them according to the actual situation.

Classification:

1) Public Oracle synonym : owned by a special user group Public . As the name implies, public synonyms are available to all users in the database. Common synonyms are often used to denote some common database objects, and these objects often need to be referenced by everyone. 2) Private Oracle synonym : it corresponds to the public synonym, which is owned by the user who created it. Of course, the creator of this synonym can control whether other users have the right to use their own private synonym through authorization. 

grammar:

Oracle synonym creation and deletion Syntax for creating public Oracle synonyms: Create [public] synonym  synonym name  for [username.]objectName ; Drop [public] synonym  synonym name  
 

4. Index

1. B-tree index (default index, saves the sorted index column and the corresponding rowid value)

1) Description:

  1. The most commonly used index in oracle; the B-tree index is a binary tree; the leaf node (doubly linked list) contains the index column and the ROWID value pointing to each matching row in the table

  2. All leaf nodes have the same depth, so regardless of the query conditions, the query speed is basically the same

  3. Can adapt to exact query, fuzzy query and comparison query

2) Classification:

   UNIQUE, NON-UNIQUE (default), REVERSE KEY (the data in the data column is stored in reverse)

3) Create example

craete index index_sno on student('sno');

 

4) Suitable for use scenarios:

  When the column cardinality (the number of unique values ​​in the column) is large, it is suitable to use the B index

  

2. Bitmap index

1) Description:

  1. When creating a bitmap index, Oracle will scan the entire table and create a bitmap for each value of the index column (in the bitmap, use one bit (bit, 0 or 1) for each row in the table) to identify Whether the row contains the value of the index column of the bitmap, if it is 1, it means that the record where the corresponding rowid is located contains the value of the bitmap index column), and finally the mapping function in the bitmap index is used to complete the bit-to-row ROWID mapping convert

2) Create an example

create bitmap index index_sno on student(sno);

3) Suitable scene:

Suitable for resume bitmap indexes for columns with small cardinality (eg gender, etc.)

 

3. Single-column index and composite index (created based on multiple columns)

1) Note:

  That is, if the index is built on multiple columns, the optimizer will use the index only if its first column is referenced by the where clause, that is, at least the first column of the composite index must be included

 

4. Function Index

1) Description:

  1. When some functions or expressions are often accessed, they can be stored in the index, so that the next time the value is calculated, the query speed can be accelerated.

  2. The function index can use either the B number index or the bitmap index; when the function result is uncertain, the B tree index is used, and the bitmap index is used when the result is a few fixed values.

  3. In the function index, you can use len, trim, substr, upper (each line returns independent results), but cannot use sum, max, min, avg, etc.

 

2) Example:

create index fbi  on student (upper(name)); select * from student where upper(name) ='WISH';

 

Summary of Indexing Principles

  1. If there are two or more indexes, one of which is unique, and the other is non-unique, in this case Oracle will use the unique index and completely ignore the non-unique index

  2. At least the first column of the composite index must be included (that is, if the index is built on multiple columns, the optimizer will only use the index if its first column is referenced by the where clause)

  3. Small tables do not need resume indexes

  4. B-tree indexes are suitable for columns with large cardinality, and resume bitmap indexes are suitable for columns with small cardinality

  5. There are many null values ​​in the column, but you should build an index when you frequently query non-null records on the column

  6. Indexes should be created on columns that are frequently queried by joins

  7. When using create index, put the most frequently queried columns first

  8. LONG (variable-length string data, up to 2G) and LONG RAW (variable-length binary data, up to 2G) columns cannot create indexes

  9. Limit the number of indexes in the table (creating indexes takes time and increases as the amount of data increases; indexes take up physical space; when adding, deleting, and modifying data in the table, indexes should also be dynamic maintenance, reducing the speed of data maintenance)


    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324811170&siteId=291194637