1. Create a table
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Create Table Test (
ID VARCHAR2 (10),
Age Number
);
2. Backup table
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
-
create as
-
select * from test group by id;
3. Delete a table
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Drop table test; --Delete table structure and table data
4. Clear the table
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
-
truncate --Empty the data table data, there is no room for return
-
delete from test; ---emptying data table data, There is room for return
5. Add Field Download
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Alter Table Test Add (
name varchar2 (10),
Interest VARCHAR2 (20)
);
6. Delete fields
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Alter table Test drop name;
7. Update data
7.1 Updating a single piece of data
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Update Test T
set t.id=' 001 '
where t.id is not null;
commit;
7.2 Updating multiple data from other tables
SQL code download 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Collection code "style=" border:0px; "/>
update Test T set T.name= (
Select TM. name
from Test_common TM
where t.id=tm.id
);
commit;
--Note: When updating data, it is best to create a separate table for SQL in the update subquery to improve the speed of updates.
7.3 Querying data in PL/SQL to change data directly into edit mode
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
-
select * for update ;
-
--Note: The update operation is finished, to lock the data table, while executing the commit action
8. Query data
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Select * from test;
9. Query the number of data sheets
SQL code Download
Select Count (0) from test;
--Note: count (0) or other numbers save database resources more efficiently and faster than COUNT (*)
10. Inserting data
10.1 Inserting multiple fields in a single piece of data
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Insert into Test (C1,C2) values(1,' Technical Department ');
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
-
insert select c1,c2 from test_common;
-
commit ;
10.2 Inserting more than one data
SQL code 650) this.width=650; "class=" star "src=" Http://1395573703.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>
Insert into Test (
Id
name,
Age
)
Select
Id
name,
Age
from Test_common;
commit;
--Note: 1. When inserting multiple data, insert INTO statement does not have values, directly splicing data query statement; 2. After you insert, UPDATE, Delete, and so on in Oracle, you perform a commit commit. Otherwise, in the system is forbidden to operate the database, because the database has been locked down, this is the database in order to prevent multiple people at the same time to modify the database data caused confusion of a preventive mechanism.
Oracle General Operations