Oracle database from getting started to mastering the second

Source: Internet
Author: User

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

Related Article

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.