Oracle SQL basics 1

Source: Internet
Author: User

Every RDBMS comes out of its own SQL features based on standard SQL. Oracle is no exception. Now, let's learn about Oracle SQL.
Learning SQL is used by developers to achieve excellent business logic. It is used by managers to optimize databases.

Oracle SQL can be divided:
A) Select
B) DML: Update, insert, delete, merge
C) DDL: Create, alter, drop
D) DCL: Grant, revoke
E) TCL: commit, roolback, savepoint

Oracle data types:
1) Integer type
Oracle does not have a special Integer type. Therefore, number (10) is used to represent an integer.
2) Value Type
Number (m, n)
M: The number of digits of all valid numbers.
N: number of digits after the decimal point
3) character type
Char (m): Fixed Length
Varchar2 (m): Variable Length, Max is m
4) Date and Time Type
Date: Date and Time Data
Timestamp: Timestamp (an electronic credential with legal benefits)
5) binary type
BLOB: Save videos, images, etc.

When writing an SQL statement, we recommend that you use a branch to write the statement, because RDBMS prompts an error message based on the row number. It can also improve readability. When using a primary key, the best practice is to use a logical primary key instead of a business primary key. Therefore, avoid using the Union primary key, because the Union primary key basically has business meaning. In addition, the joint primary key is not suitable for creating foreign key constraints.

The foreign key is the third dimension of the relational database. Definition: foreign key (field name) References target table name (referenced field name ). Complex services are implemented through foreign key constraints.

Modify an existing data table
Add field: alter table table_name add field Name field type;
Delete field: alter table table_name drop field name;

If a foreign key association exists between tables, an error is returned when you execute drop table table_name on the referenced table. You must delete the referenced table first!

For some restricted operations, we can create a new table to replace the functions we want.

The above interviews are all about table operations. Next, let's talk about data operations.

With foreign key constraints, the inserted data must exist in the referenced table. Update a table. Multiple columns can be updated after set, separated by commas. Add the WHERE clause to filter the required rows.

Delete from table_name where... is to eat the rice in the bowl; drop table... is to eat the rice in the bowl and then smash the bowl.

Oracle seldom involves double quotation marks. Column alias. Double quotation marks allow us to control the output format of column names.

Null occupies almost no storage space. If you select null or 0, we recommend that you store null instead of 0.

For fields with '_' or '%' headers, escape them during fuzzy search. For example:
Like '\ % 'escape '\'
Like '\ _ % 'escape '\'

The usage of aggregate function count is slightly different. For example:
Count (*): Total number of statistical result sets
Count (name): Total number of records whose name is not null in the statistical result set

For multiple sorting rules of order by, order by first sorts by the first sorting rule. If the first sorting rule cannot distinguish the order of two records, sort by the second sorting rule. If the second sorting rule cannot distinguish the order of two records, sort by the third sorting rule, and so on.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.