Maintenance of Oracle data (CRUD)

A, SQL

1.SQL-Structured Query Language Structured Query Language, a database query and programming language, published by the ISO standardization organizations.

2.SQL oriented set of operations, described only demand, regardless of the process, how to complete by the DBMS is responsible for resolving.

3.SQL languages ​​including DDL and DML language

①create table, alter table, drop table, and the like belong to truncate table DDL language.

②insert, update, delete, etc. to select and DML language

Second, the most commonly used functions and operators

1. Arithmetic operators: +, -, *, /;

2. assignment operator: =;

3. The string concatenation operator: ||;

4. The modulo operator (remainder operator) function: mod (dividend, divisor).

The logical operators

Operators

meaning

AND

And both are connected to two Boolean expressions returns TRUE is TRUE

OR

Connecting the two boolean expressions and one of them returns TRUE is TRUE

NOT

Any Boolean expression negated

IN

Return TRUE if the operand is equal to one of a list of expressions

BETWEEN

Returns TRUE if the operands within a certain range

LIKE

Returns TRUE if the operands and string pattern matching

EXISTS

TRUE when the query result is not empty

Three, SQL wildcard

String Wildcard 

Wildcards

meaning

%

Specify the location of zero or more characters

_

There are characters in a designated location

Example:

① search all names to 'tom' start, you can specify a search condition LIKE 'tom%';

② In the title search is the third character 'k' of the recording, to specify a search condition LIKE '__k%';

③ names included in the search 'West' recording can be specified as the search condition LIKE '%% west'.

Four, select statement

1.select statement is to extract records from a relational database SQL statement, SELECT statement does not update any of the data in the table.

2.select statement may be a simple "select * from table name" query all records from a table or view in all fields, you can also attach a lot of query clauses.

For example: select [distinct] <Results field list> from <table / view name> 

[Where <query>]

[Group by <packet field>]

[Having <Packet Filters>]

[Order by <field sort> [desc | asc]]

[for update]

3. The value of the field can be used directly in the operation result field list, query and packet filters select statement can be used in the calculation result column values.

Five, insert statements

1.insert statement adds a new row to the table, the syntax is as follows:

insert into table_or_view [(column_list)]  values(value_list)

2.insert statement batch add more new rows to a table, the syntax is as follows:

insert into table_or_view [(column_list)]   select 子句

3.insert insert statement specifies one or more rows of the table or view. column_list is a list of column names, column names separated by commas, to provide data for the specified column for. If not specified, all the columns in the table or view data are received. When all the columns in the table or not column_list view is designated, the system uses the default value (if column defines the default) or not NULL is inserted in the list specified in any one. All columns that are not specified in the list must allow null values ​​or assign default values. 4.insert value statement identifies the type of the column is not specified, because the Oracle database instance to generate values ​​for these columns.

Six, update statement

1.update statement can change the table or view the data values ​​a single row, all rows or groups of rows. Refer to a table or view UPDATE statement can only change the data in a base table.

update table_or_view set column_name = { expression | DEFAULT | NULL } , column_name = { expression | DEFAULT | NULL } ,  …… where search_condition

2.update statements include the following main clauses:

①set: column contains a list to be updated and new values ​​for each column (separated by commas) format column_name = expression. Expression values ​​comprises providing a plurality of items, such as constants, selected from a list of other values ​​in the table or view or use complex expressions calculated value.

②where: specifying search criteria, the search criteria to define the source tables and views row values ​​may be provided to the SET clause expressions.

Seven, delete sentence

①delete statement removes the table one or more lines, delete or view the grammatical forms as:

delete table_or_view   where search_condition

② table or view from which you want to delete the specified parameters table_or_view line. table_or_view in all rows meet the WHERE criteria will be deleted. If you do not specify a WHERE clause to delete all the rows table_or_view.

③ any deleted all the rows of the table remains in the database. delete statement deletes only rows from a table, deleted from the database table, you can use the drop table statement.

Eight, merge statement - Consolidated statement rows

Merge statement data using the source table to the target table data is updated, i.e., by providing the matching conditions may be updated or inserted field.

Nine, truncate statement

1.truncate statement belongs to DDL statements

Function: delete all the rows in the table, without recording the operation log.

2.truncate table with no where clause of the same statement on the delete function; however, truncate table faster, system resources, and transaction logs using fewer resources.

语法:truncate table table_name

Example: Delete all the recording without recording operation log truncate table report.

 

Published 74 original articles · won praise 32 · views 9970

Guess you like

Origin blog.csdn.net/qq_41629684/article/details/104412984