Add, delete, modify, and query statements for oracle,
Create a table:
Cteate table name (column 1 type,
Column 2 );
View table structure desc table name
Add a field alter table name add (column type );
Alter field type alter table name modify (column type );
Delete the alter table Name drop column name;
Rename student to stu
Drop table name
Insert data:
1. create table test (
Id number,
Name varchar2 (20 ),
Age number (2)
);
2,
Insert into table name values (values of all columns );
Insert into test values (1, 'hangsan ', 20 );
The inserted data should be of the same type as the field data.
The data size should be within the specified range of the column.
The data positions listed in values must correspond to the arranged positions of the columns to be added.
3,
Insert into Table Name (column) values (corresponding value );
Insert into test (id, name) values (2, 'lisi ');
Update statement:
Update table set column = new value [where condition] -- "update records meeting the condition
Update test set name = 'hangsan2' where name = 'hangsan'
Update table set column = new value -- "update all data
Update test set age = 20;
Delete data:
1. delete from table name where condition -- delete records that meet the condition
Delete from test where id = 1;
Delete from test --> delete all
Commit; -- submit data
Rollback; --> Roll Back data
2. truncate table name
Deleting all data does not affect the table structure, logs are not logged, and data cannot be restored. -- "is deleted quickly.
3. drop table name
Deleting all data, including the table structure, does not record logs, and data cannot be restored. -- "deleted quickly
How long is an SQL statement executed: set timing on
How to quickly copy data: 1. insert into test select * from test;
2. create table Name select * from test;
Import data: @ file name
Distinct display: select distinct column from Table Name
Date type: to_date (string 1, string 2) string 1 is the date string, string 2 is the format
To_date ('1970-1-1 ', 'yyyy-mm-dd') --> the type of the returned date is 1990-1-1.
Fuzzy query of SQL: like
Sort the order by field in the query result
Select * from emp order by sal --> after order by, the default value is ascending.
Asc ascending desc descending
Group by field -- sort by specified field in ascending order
Having words -- "filters and outputs The Structure After grouping