List common Oracle commands

Source: Internet
Author: User

The following articles mainly introduce common Oracle commands, including Oracle data types, views, and instances. If you are a beginner in common Oracle commands, if you know more about the applications of common Oracle commands, click the following article.

Oracle Data Type:

 
 
  1. Create table test1 (name char (10), sex char (1 ));
  2. Insert into test1 values ('att Beijing', 'F ');
  3. Create table test2 (name nchar (10), sex nchar (1 ));
  4. Insert into test2 values ('att Beijing', 'male ');

Drop table Name of the table to be deleted;

 
 
  1. Create table test3 (name varchar2 (10), sex varchar2 (2 ));
  2. Insert into test3 values ('att Beijing', 'F ');

The inserted value is too large.

 
 
  1. Insert into test3 values ('tomcat Beijing', 'F ');
  2. Create table test4 (name varchar2 (10), age number (3 ),
    Salary number (8, 2 ));
  3. Create table test5 (name varchar2 (10), birth date );
  4. Insert into test5 values ('Tom ', '28-January 1, February-08 ');
  5. Insert into test5 values ('allen ', sysdate );

DDL:

Create a table

 
 
  1. create table scott.test6(  
  2. eid number(10),  
  3. name varchar2(20),  
  4. hiredate date default sysdate,  
  5. salary number(8,2) default 0  
  6. )  

If hiredate and salary are not specified during data insertion, the default value is used.

The following describes Oracle data dictionary in common Oracle commands:

Dba-object information contained in all solutions

All-object information that users can access

User-object information of the User Solution

 
 
  1. Select * from user_tables;  
  2. Select * from all_tables;  

Constraints:

Domain integrity constraints: not null check

Entity Integrity Constraint: unique primary key

Integrity constraints: foreign key

View:

 
 
  1. Create or replace view v1(eid,name,salary) as select 
    empno,ename,sal from emp where deptno = 30; 

Sequence: sequence

 
 
  1. Create sequence mysequence1 increment by 1 start
     with 1 nomaxvalue nocycle;  
  2. Insert into test values(mysequence1.nextval,’tom’);  
  3. Create sequence student_sequence start with 1
     increment by 1;  
  4. Insert into student values
    (student_sequence.nextval,’john’);  

Copy data between tables:

 
 
  1. Insert into dept1(id,name) select deptno,
    dname from dept; 

Instance creation table ID field auto-increment ):

 
 
  1. create table test2(id char(10) primary key not null,
     name char(10));  
  2. create sequence test2_sequence increment by 1 start
     with 1 nomaxvalue nocycle;  
  3. insert into test2 values(test2_sequence.nextval,'john');  
  4. insert into test2 values(test2_sequence.nextval,'allen');  
  5. insert into test2 values(test2_sequence.nextval,'candy');  
  6. insert into test2 values(test2_sequence.nextval,'aaaa');  
  7. insert into test2 values(test2_sequence.nextval,'bbbbb');  
  8. insert into test2 values(test2_sequence.nextval,'cccccc');  
  9. insert into test2 values(test2_sequence.nextval,'ddddd');  
  10. insert into test2 values(test2_sequence.nextval,'eeeee');  
  11. insert into test2 values(test2_sequence.nextval,'ggggg');  
  12. insert into test2 values(test2_sequence.nextval,'jowwwwhn');  
  13. insert into test2 values(test2_sequence.nextval,'aaaadd');  
  14. insert into test2 values(test2_sequence.nextval,'ggghhh');  
  15. insert into test2 values(test2_sequence.nextval,'eeettt');  
  16. insert into test2 values(test2_sequence.nextval,'wwwttt');  
  17. select * from test2;  

View table structure

EDITDATA table name;

Modify Table fields:

Alter table name modify (field name type constraints );

Alter table test modify (addd varchar2 (10) null );

Alter table name add (field name type constraints );

Alter table test add (age varchar2 (5 ));

The above content is a description of common Oracle commands, hoping to help you in this regard.

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.