DB Basic Statement (Oracle)

Source: Internet
Author: User

I. SQL Classification

DDL: Data Definition language (Language)

DML: Data manipulation language (manipulation Language)

TCL: Transaction Control Language (Transaction control Language)

DQL: Data Query Language (Language)

DCL: Data Control Language (Language)


1. DDL

Used to create, modify, and delete database objects

Creae: Creating a table or other object structure

Alter: Modify the structure of a table or other object

Drop: Delete the structure of a table or other object

TRUNCATE: Deleting table data, preserving table structure

2. DML

Insert: Inserting data into a data table

Update: Updating data that already exists in the data table

Delete: Delete data from a database table


3. TCL

Commit: Commit, confirm the data changes that have been made

ROLLBACK: Rollback, cancellation of data changes already in progress

SavePoint: Save point so that the current transaction can be rolled back to the specified savepoint, making it easy to undo some changes


4. DQL

SELECT


5. DCL

Grant: Granted to grant permissions to a user or role

REVOKE: Used to retract a user's or role's existing permissions

Create User: Creating users


Two. Oracle Basic type

1. Number (numeric type)

Number (P,s): P represents the total number of digits; S represents the number of digits after the decimal point


2. CHAR (fixed length character type)

CHAR (n): n Indicates the number of bytes occupied, the maximum length is 2000 bytes

No matter how long the given value is, the byte will occupy N bytes.


3. VARCHAR2 (variable-length character type)

VARCHAR (n): n represents the maximum number of bytes that can be consumed, and the maximum length is 4000 bytes

The given value is how long it takes to take a byte, but it is not conducive to frequently changing characters, because the previous characters need to be recalculated, and the performance is Vchar poor.

There are also varchar in Oracle, as in MySQL, where varchar is the same as VARCHAR2, but varchar may change with the general consent rule, and VARCHAR2 will never change, and is a variable long character type.


4. Date (date-time data defined)

Length: 7 bytes

Default format: DD-MON-RR (eg:11-apr-71)

Where the RR year is as follows:

Current time (column)/system time (ROW) 0–49 50–99
0–49 Century Next century
50–99 Last century Century


Three. Basic syntax

1. CREATE TABLE table_name (ID number (4));

2. View TABLE Structure DESC table_name

3. Assigning a default value to a field when creating a table

4. Non-null (NOT NULL) condition constraint to ensure that the field value is not empty

5. Modify the table name

RENAME Old_name to New_name;


6. Add columns

ALTER TABLE table_name ADD (column Datatype[default expr][column datatype ...])

Columns can only be added at the end and cannot be inserted into existing columns (MySQL can be inserted after the specified column)

Eg: add a column of Hiredata to the table and set the default value to the current date

ALTER TABLE myemp ADD (hiredate DATE DEFAULT sysdate);


7. Delete Columns

ALTER TABLE table_name DROP (column);

Deleting a field requires removing the length and data occupied by the field from each row and freeing the space occupied in the data block, and deleting the field may take a long time if the record is larger.


8. Modifying columns

ALTER TABLE table_name MODIFY (column datatype [DEFAULT expr][column datatype ...])

You can change the data type, length, and default values of the columns in the table after you build the table

Modification is only valid for data inserted later

If you change the length from big to small, you may not succeed.

Eg:modify TABLE myemp MODIFY (Job VARCHAR2 (+) DEFAULT ' clerk ');


9. Inserting data

INSERT into table_name (column1, Column2) VALUES (value1,value2);

After a DML operation is performed, the commit statement needs to be executed before the operation is truly confirmed.

If you insert a column that has a date field, you need to consider the format of the date. The default date format is ' DD-MON-RR ', you can customize the date format and use the To_date function to convert to date type data

Eg:insert into myemp (ID, name, job, birth) VALUES (1002, ' DOMA ', ' MANAGER ', to_date (' 2009-01-01, ' yyyy-mm-dd '));


10. Update operations

UPDATE table_name SET column = value WHERE id = 2;


11. Delete operation

DELETE from table_name = where id = 2;

The TRUNCATE statement in the DDL statement also has the effect of deleting the table data.

and DELETE statements differ:

-delete can be conditionally deleted, truncate all table data is deleted

-delete is a DML statement that can be returned, TRUNCATE is a DDL statement that immediately takes effect and cannot be rolled back

-Delete statements are less efficient than TRUNCATE statements if all table records are deleted and the amount of data is large

Transaction control:

Commit for Transaction commit

The rollback is used to roll back the transaction. Then all the additions and deletions in the transaction failed.


DB Basic Statement (Oracle)

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.