oracle基础

来源:互联网 发布:网络翻唱女歌手曼里 编辑:程序博客网 时间:2024/06/01 15:24

1.Oracle常见字段类型解析

   varchar2(len)      可变长度的字符串,长度必须规定; 
 char(len)        固定长度的字符串,默认长度为1; 
 number(len, p)     数值型,len为位数总长度,p为小数长度; 
 date          日期和时间类型; 
 clob          文本大字段类型; 
 blob          二进制大字段类型。

2.Oracle默认值和约束

默认值: 
 日期和时间类型 default sysdate,在执行插入或修改操作时,不用程序操作这个字段,系统会默认设置成当前时间。 
约束: 
 非空约束 not null; 
 唯一约束 unique; 
 按条件检查 check (条件); 
 主键 primary key; 
 外键 references 表名(列名)。

3.Oracle建表语句

   create table 表名( 
  列名1 字段类型1, 
  列名2 字段类型2, 
  …. 
  列名n 字段类型n 
 ); 
   例:
create table user (    id                 number(19) not null primary key,    code               varchar2(50) not null,    name               varchar2(50) null,    password           varchar2(255) null);comment on table user is '用户';comment on column user.id is '主键';comment on column user.code is '用户编码';comment on column user.name is '用户名称';comment on column user.password is '密码';

4.Oracle添加、修改、删除字段

添加
alter table user add(valid int);comment on column user.valid is '有效标识(0无效 1有效)';
修改 
 修改字段类型:
alter table user modify valid boolean;comment on column user.valid is '有效标识(true有效,false无效)';
   修改字段长度:
alter table user modify password varchar2(20);
删除
alter table user drop (valid);

5.Oracle查看注释

查看表注释:
select * from user_tab_comments where TABLE_NAME='table_name';
查看字段注释:
select * from user_col_comments where TABLE_NAME='table_name';











0 0