以下的文章主要是介绍Oracle常用命令,其中包括Oracle数据类型,视图,以及实例的相关的介绍,如果你是Oracle常用命令方面的新手,相对Oracle常用命令的相关应用方面有所了解的话,你就可以点击以下的文章。
Oracle数据类型:
Create table test1(name char(10),sex char(1));
Insert into test1 values(‘tomcatt北京’,’f’);
Create table test2(name nchar(10),sex nchar(1));
Insert into test2 values(‘tomcatt北京’,’男’);
- 1.
- 2.
- 3.
- 4.
删除表 drop table 表名;
Create table test3(name varchar2(10),sex varchar2(2));
Insert into test3 values(‘tomcatt北京’,’f’);
- 1.
- 2.
插入值过大
Insert into test3 values(‘tomcat北京’,’f’);
Create table test4(name varchar2(10),age number(3),
salary number(8,2));
Create table test5(name varchar2(10),birth date);
Insert into test5 values(‘Tom’,’28-2月-08’);
Insert into test5 values(‘Allen’,sysdate);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
DDL:
创建表
create table scott.test6(
eid number(10),
name varchar2(20),
hiredate date default sysdate,
salary number(8,2) default 0
)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
插入数据时若没有指定hiredate,salary的话则会取默认值
以下就是Oracle常用命令中Oracle数据字典的相关介绍:
Dba-所有方案包含的对象信息
All-用户可以访问的对象信息
User-用户方案的对象信息
Select * from user_tables;
Select * from all_tables;
- 1.
- 2.
约束:
域完整性约束:not null check
实体完整性约束:unique primary key
参照完整性约束:foreign key
视图:
Create or replace view v1(eid,name,salary) as select
empno,ename,sal from emp where deptno = 30;
- 1.
- 2.
序列:sequence
Create sequence mysequence1 increment by 1 start
with 1 nomaxvalue nocycle;
Insert into test values(mysequence1.nextval,’tom’);
Create sequence student_sequence start with 1
increment by 1;
Insert into student values
(student_sequence.nextval,’john’);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
表间数据拷贝:
Insert into dept1(id,name) select deptno,
dname from dept;
- 1.
- 2.
实例(创建表 ID字段自增):
create table test2(id char(10) primary key not null,
name char(10));
create sequence test2_sequence increment by 1 start
with 1 nomaxvalue nocycle;
insert into test2 values(test2_sequence.nextval,'john');
insert into test2 values(test2_sequence.nextval,'allen');
insert into test2 values(test2_sequence.nextval,'candy');
insert into test2 values(test2_sequence.nextval,'aaaa');
insert into test2 values(test2_sequence.nextval,'bbbbb');
insert into test2 values(test2_sequence.nextval,'cccccc');
insert into test2 values(test2_sequence.nextval,'ddddd');
insert into test2 values(test2_sequence.nextval,'eeeee');
insert into test2 values(test2_sequence.nextval,'ggggg');
insert into test2 values(test2_sequence.nextval,'jowwwwhn');
insert into test2 values(test2_sequence.nextval,'aaaadd');
insert into test2 values(test2_sequence.nextval,'ggghhh');
insert into test2 values(test2_sequence.nextval,'eeettt');
insert into test2 values(test2_sequence.nextval,'wwwttt');
select * from test2;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
查看表结构
EDITDATA 表名;
修改表字段:
Alter table 表名 modify(字段名 类型 约束);
alter table test modify (addd varchar2(10) null);
alter table 表名 add(字段名 类型 约束);
alter table test add(age varchar2(5));
上述的相关内容就是对Oracle常用命令的描述,希望会给你带来一些帮助在此方面。
【编辑推荐】