Focus on table creation and operation syntax (how to create and design table is something)
Common data types
A table is essentially a collection of data operations
Data type:
No matter how many types of data you extend, the following are some common
The string varchar2 (the other database is varchar) is described, and 200 characters are used with this type of class.
Numeric number to describe, decimal with number (m,n), where n is the decimal place, and m-n is the integer digit.
The database also takes into account the habits of the program staff:
integers are represented by Int.
Decimals are represented by float.
Dates Date
Large text data Clob to describe, up to 4G of text can be saved.
Large object data blob to describe, picture, music, video, text, can save up to 4G,
Although it can be saved, but inefficient, the database is more to save the address, the cost of
Half a day, save in, still have to spend half a day to read out, the database is exhausted.
In terms of actual development, mastering these four is enough, Varchar2,number,date,clob.
#########################
Table creation:
CREATE TABLE Table name (
Column name data type [default defaults],
Column name data type [default defaults],
Column name data type [default defaults],
Column name data type [default defaults],
...
Column name data type [default defaults]
);
CREATE TABLE member (
Mid number,
Name VARCHAR2 (default ' Noname '),
Birthday Date Default Sysdate,
Note CLOB
Insert into member (Mid,name,birthday,note) VALUES (1, ' AA ', to_date (' 1980-09-08 ', ' yyyy-mm-dd '), ' aaaaaaaaaaaaaa ');
Insert into member (Mid,name,birthday,note) VALUES (2, ' BB ', to_date (' 1980-10-08 ', ' yyyy-mm-dd '), ' bbbbbbbbbbbbbb ');
Insert into member (mid) values (3);
Insert into member (Mid,name) values (4,null);
If NULL is specified, the default value is overwritten.
############################
Table replication
Saves the results of the subquery as a data table.
Create TABLE table name as sub-query;
Simple query
CREATE TABLE Emp30 as SELECT * from EMP where deptno=30;
Complex queries
CREATE TABLE Deptstat
As
Select D.deptno,d.dname,temp.count,temp.avg
From Dept D, (
Select Deptno Dno,count (*) Count,avg (SAL) Avg
From EMP
GROUP BY Deptno) Temp
where D.deptno=temp.dno (+);
In addition to replicating table data, you can copy only the table structure.
Just set a condition that is absolutely impossible to meet.
CREATE TABLE Empnull
As
SELECT * from EMP where 1=2;
Oracle database from getting started to mastering the second