以下的文章主要是介绍Oracle常用的命令中Oracl的相关数据类型,本文也涉及到一些相关的实际应用代码,以代码的方式来引出Oracle常用的命令中Oracl的相关数据类型,以下就是文章的具体介绍。
- 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北京’,’男’);
删除表 drop table 表名;
- Create table test3(name varchar2(10),sex varchar2(2));
- Insert into test3 values(‘tomcatt北京’,’f’);
插入值过大
- 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);
- DDL:
创建表
- create table scott.test6(
- eid number(10),
- name varchar2(20),
- hiredate date default sysdate,
- salary number(8,2) default 0
- )
插入数据时若没有指定hiredate,salary的话则会取默认值
Oracle常用命令数据字典:
Dba-所有方案包含的对象信息
All-用户可以访问的对象信息
User-用户方案的对象信息
- Select * from user_tables;
- Select * from all_tables;
约束:
域完整性约束: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;
序列: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’);
Oracle常用命令表间数据拷贝:
- Insert into dept1(id,name) select deptno,dname from dept;
实例(创建表 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;
查看表结构
EDITDATA 表名;
修改表字段:
Alter table 表名 modify(字段名 类型 约束);
- alter table test modify (addd varchar2(10) null);
alter table 表名 add(字段名 类型 约束);
- alter table test add(age varchar2(5));
【编辑推荐】