SQL-based learning
1, SQL statements are divided into the following three types :
①, DML (the Data Manipulation Language) : data manipulation language
②, DDL (the Data Definition Language) :: Data Definition Language
③, the DCL (the Data Control Language) : Data Control Language
- DML is used to query and modify data records, including the following SQL statement:
INSERT : add data to the database
UPDATE : modify data in the database
DELETE : delete data in the database of
the SELECT : (. Is the basis of the SELECT SQL language, the most important) to select (query) data
- DDL defines the structure of the database, such as creating, modifying or deleting database objects, including the following SQL statement:
TABLE the CREATE : create database tables
the ALTER TABLE : change the table structure, add, delete, modify the column length
DROP TABLE : Table delete
the CREATE INDEX : index on a table
DROP INDEX : Delete Index
- DCL is used to control access to the database, including the following SQL statement:
GRANT : grant access to
REVOKE : revoke access
COMMIT : to commit the transaction
ROLLBACK : transaction rollback
SAVEPOINT : savepoint set
LOCK : to lock certain parts of the database
2, using SQL Precautions
SQL language is not case sensitive.
SQL can be written in one or more rows
Keywords can not be abbreviated nor branch
Each clause is generally branches write.
Use indentation to improve readability statement.
3, arithmetic operator
-
Transport operators count numbers and dates of use: +, -, *, /
-
Operator precedence:
Subtraction, multiplication and division higher priority than
the same priority are performed from left to right operator
operation to perform in brackets
4, a null value is defined:
Null value is invalid, unspecified, unknown or unpredictable value is
null or not a space 0
5, the column aliases:
Renaming a column, easy to calculate.
Followed column names, keywords may be 'AS' between the column name and alias, double quotes, in order to contain spaces or special characters in the alias and is case sensitive.
6, connector:
The column together with the column, the column and character.
Indicated by '||'.
It can be used to 'synthesis' columns, such as: System.out.println (123 + "hello" + 123); -> 123hello123
7, the string:
The string may be a character in the SELECT list, numbers, dates.
Date and character can only appear in single quotation marks.
Whenever the return line, a character string is output.
Such as:
-------- filter criteria: date 1980-12-17 recruits --------
the SELECT * A A emp from the WHERE a.hiredate = '17 - December -1980. ';
. A SELECT * from EMP WHERE A TO_CHAR (a.hiredate,' the MM-dd-YYYY ') =' 1980-12-17 ';
8, delete duplicate lines:
By default, the query returns all rows, including duplicate rows, use the keyword 'DISTINCT' in the SELECT clause to delete duplicate rows. Such as: select distinct depart_id from employees;
SQL and SQL * Plus
- Using SQL * Plus can do? :
Described table structure.
Edit SQL Statement.
Execute SQL statements.
SQL will be saved in a file and save the results of SQL statements in a file.
Executing a statement in saved files.
The text file into SQL * Plus edit window.
- Comparison Operators
- Other comparison operation
-------- m is the name of the second employee --------
SELECT * from A a.ename like EMP WHERE A '_M%'.;
-------- employees _ containing the names of employees who '' represent the escape character --------
the SELECT A. * A emp from the WHERE a.ename like '% _%' Escape ' ';
- priority
Sequence
order by default field to be sorted from small to large
desc descending asc small to large
-------- multiple sort, if the wages from high to low sort, if the wages of the same name from low to high ranking --------
the SELECT A. *, A.rowid from the Order by A A emp .sal desc, a.ename asc
-------- alias sorted according --------
SELECT a.ename, a.sal A * EMP 12 is yearSal from desc Order by yearSal
The next chapter, (2) Oracle ------ one-way function and multi-table queries