以下的文章主要是介紹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));