数据库

 首页 > 数据库 > Oracle > Oracle表的管理简析

Oracle表的管理简析

分享到:
【字体:
导读:
         摘要:1、表名和列的命名规则字母开头、不超过30个字符、不能使用保留字只能使用A-Z,a-z,0-9,$,#等2、数据类型字符型www.2cto.com... SyntaxHighlighter.all(); ...

Oracle表的管理简析

1、表名和列的命名规则
 
                   字母开头、不超过30个字符、不能使用保留字
 
                   只能使用A-Z,a-z,0-9,$,#等
 
         2、数据类型
 
                   字符型  www.2cto.com  
 
                   (1)、char 定长 2000字符
 
例如:        char(10) ‘张三’ 前四个字符放’张三’后面6个空格
 
优点:        查询时效率高
 
缺点:        占空间多
 
                   (2)、varchar2(20) 变长 4000个字符
 
                            优点:        节省空间
 
                            缺点:        查询效率没有char高
 
                   (3)、clob(character large object)
 
                   数值型
 
                   (1)、number    范围-10的38次方到10的38次方 (整数或小数)
                   www.2cto.com  
                   (2)、number (5,2)   表示一个小数有5位有效数,2位小数
 
                            例子:        number(5,2)范围     -999.99~999.99
 
                   (3)、number(5)        表示一个五位的整数-99999~99999
 
                   日期类型
 
                  (1)、date                   包含年月日和时分秒
 
                   (2)、timestamp       对date数据类型的扩展
 
                   图片
 
                   (1)、blob          二进制数据可以存放图片/声音 最大4G
                 
         2、建表
 
create table student(       --学生表
 
                   Xh     number(4),       --学号
 
                   Xm   varchar(20),     --姓名
 
                   Sex   char(2)     ,        --性别
                    www.2cto.com  
                   Birthdaydate,          --出生日期
 
                   Sal    number(7,2))   --奖学金
 
                  
 
                   Create tableclasses(       --编辑表
 
                   Classidnumber(2),
 
                   Cnamevarchar2(40));
 
 
         3、添加一个字段
 
alter table student add (classid number(2));   
 
                   4、修改字段长度
 
                                     alter table student modify (xm varchar2(30));
 
                   5、修改字段的类型/或是名字(不能有数据)
 
                                     Altertable student modify (xm char(30))
 
                   6、删除一个字段(在公司一般不使用,会影响别人)
 
                                     Altertable student drop column sal;
 
                   7、修改表的名称
 
                                     Renamestudent to new_student;
 
                   8、删除表
 
                                     Droptable student;
 
                   9、添加数据   www.2cto.com  
 
insert into student(xh,xm,sex,birthday,sal) values (2,'小红','女','1989-4-1',200);                                    
 
                   10、修改一个字段
 
                                     Updatestudent set sex=’女’ where xh=3
 
                   11、修改含有空值的数据     is null
 
                   12、删除数据
 
                            (1)、delete table student;       可以恢复,速度慢
 
                            (2)、truncate table student;  不能恢复,速度快,不写日志
 
                   13、savepoint 保存点名称
 
                            Deletefrom student;
 
                            Rollback   to 保存点名称;
                        www.2cto.com  
                   14、set timing on查看查询时间
 
                   注意:        Oracle 中默认的日期格式’DD-MON-YY’
 
                                     alter session set nls_date_format='yyyy-MM-dd';
 
 
 
作者 liyangfd
Oracle表的管理简析
分享到:
oracle 11g完全卸载方案
oracle 11g完全卸载方案 1.关闭oracle所有的服务。可以在windows的服务管理器中关闭;         2.打开注册表:regedit 打开路径:     HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\     删除该路径下的所有以oracle开始的服务名称,这个键是标识Oracle在windows下注册的各种服务!     www.2cto.c...
Oracle月初和月底时间的查询
Oracle月初和月底时间的查询 什么时候需要用到这2个时间,先简单说下: 假如你3月15日订购的包月产品,月底出帐,那么应该收取17天的费用,这个时候就应该判断订购时间是否大于月初时间。 如果你只用到了3月25号,那么应该收取11天,这个时候你就需要判断使用时间是否小于月底时间。而订购时间和使用时间 是一般是存在于...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……