Oracle common commands

/ ** For clarity of the display: All commands are capitalized fixed format

SQL syntax Category: DML, DDL, DCL

(1) DML (Data Manipulation Language, a database manipulation language):

         Data: add, modify, delete

(2) DDL (Data Definition Language, a database definition language):

          Define the structure of the data table, defined (user data table, model name) of database objects

(3) DCL (Data Control Lanaguage, Data Control Language): Authorization Manager

SQL statement execution order: ①FROM, ②WHERE, ③SELECT

 

**/

1.Oracle common commands:

Start Oracle: (1) First check service option "OracleServiceXXX", "OrcaleOraDbllg_home1TNSListener" whether to activate two services;

                     (2) Open the "Run" or enter cmd into the command line interface, type:

                             "Sqlplus" or

                             "Sqlplus username / password"

2. Set the structure of the display:

                      (1) SET LINESIZE 100; // set per line length

                      (2) SET PAGESIZE 30; // set of data lines per page number           

                      (3) COL tname FOR A20; // explicitly set the column format

 

3. User Switching:

CONN [ECT] username / password [AS SYSDBA | SYSUSER] // Switch User

For example: CONN sys / change_on_install AS SYSDBA // change to the superuser

CONN system / manager // switch to common user

 

4. Basic statement:

SELECT * FROM tab; // query all the tables under the name of the current database

DESC table name; // view the structure of the table

SELECT * FROM table name; // query all the information in the table

. SELECT * FROM user name table name; // specify the user name, look-up tables under the user

SELECT column name [alias], column name [alias] .... FROM table name; // query information specified column

SELECT column name AS alias FROM table; // Define the table name, Oracle statement AS can be omitted

SELECT job, sal * 10 + 20 * 10 as income FROM emp; // query career, 10 times the monthly salary multiplied by 10 plus 20

The SELECT the DISTINCT  column names FROM table; // remove duplicate query sequence information and the information therein, the DISTINCT deduplication

SELECT 'constant', column names FROM table; // query constant, constant need to use the '   '  '( single quotes ), including up

SELECT 'constant' ||  column names FROM table; // use " || " connection for data display 

HOST copy d: \ hello \ a.txt d: copy hello \ b.txt // perform file \

 

5. Query defined

Defining a query, execute basic statement:

③SELECT [DISTINCT] column name [alias]   

①FROM table name [alias]

②WHERE qualification;

 

Analyzing common (performance operators is greater than a plurality of operators):

  • relational operators:>, <,> =,> =, =, =;!

  • Logical operators: AND, OR, NOT [Non];

  • special operators: BETWEEN ... AND, IN, NOT IN, LIKE,

  • "  % ": match 0, 1 or any number of characters

  • "  _   ": matches any one character

SELECT * FROM table name the NOT the WHERE    (  Age> 10 SAL OR <100 000   ) ; // table query younger than 10 or higher wages 100,000 personnel information, attention parentheses

SELECT * FROM table ename the LIKE the WHERE 'A % '; // query all names beginning with A

SELECT * FROM table ename the LIKE the WHERE ' _ A %  '; // query for all second name beginning with A

SELECT * FROM table ename the LIKE the WHERE ' % A %  '; // query all arbitrary bit A Name

 

6. Sort query:

SQL statement execution order

③SELECT [DISTINCT] column name [alias]   

①FROM table name [alias]

②WHERE qualification;

④ [ORDER BY sort field names [ASC | DESC]]

 

BY the ORDER : The Sort Field

The ASC : ascending order, if the type of sorting is not set, using the default ascending

DESC : descending order, shall be manually set

* The FROM emp the SELECT the ORDER BY SAL DESC ; // query in descending order according to salary

* The FROM emp the SELECT  the WHERE Age = 11 the ORDER BY  SAL  DESC  ; // Query the age of 11 pay according to descending order

* The FROM emp the SELECT   the WHERE  Age = 11  the ORDER BY  SAL  DESC , the HireDate ASC ; // Query the age of 11 pay according to descending order, the entry date in ascending order

 

Guess you like

Origin www.cnblogs.com/fcitx/p/11330757.html