首页 > 代码库 > 5.创建表,使用alter进行表信息的增删改,Oracle回收站,集合运算

5.创建表,使用alter进行表信息的增删改,Oracle回收站,集合运算



1 Oracle基于用户的管理方案

2 DDL语句可以管理数据库的对象有:视图  索引 序列 同义词  约束

3 创建一个表,有2个条件(1有权限;2有表空间)

  Oracle给你提供了默认的resource.

4创建表,表信息的增删改,Oracle回收站

DDL

        管理数据库的对象

                  

                  视图索引 序列 同义词约束(..... )

 

        oracle基于用户的管理方案

                  借助于管理工具可以方便看到数据库各个对象....

 

1创建一个表

                           2个条件(1有权限 2 有表空间)       

                           oracle给你提供了默认的resource,

create table t4(tid number, tname varchar2(20), tname2 char(6));

 

insert into t4 () values(1, ‘12‘)

oracle的数据类型:        

        a) VARCHAR2(size) 可变和定长区别

        b) varchar2()  不能超过4096

        c) oracle的数据类型支持可见字符存储和不可字符的存储,存图片 

                           

---创建并且copy

        create + as

        

        create table t5

        as

                  select *from emp;

----查看别的用户下的表 

                  select * from  scott.emp;

 

-- rowid 行地址索引时候用

                           SQL> select rowid, empno, ename from emp;

                           

                           ROWID                   EMPNO ENAME

                           ------------------ ---------- ----------

                           AAAMfPAAEAAAAAgAAA       7369 SMITH

                           AAAMfPAAEAAAAAgAAB       7499 ALLEN

                           AAAMfPAAEAAAAAgAAC       7521 WARD

                           AAAMfPAAEAAAAAgAAD       7566 JONES

                           AAAMfPAAEAAAAAgAAE       7654 MARTIN

                           AAAMfPAAEAAAAAgAAF       7698 BLAKE

                           AAAMfPAAEAAAAAgAAG       7782 CLARK

                           AAAMfPAAEAAAAAgAAH       7788 SCOTT

                           AAAMfPAAEAAAAAgAAI       7839 KING

                           AAAMfPAAEAAAAAgAAJ       7844 TURNER

                           AAAMfPAAEAAAAAgAAK       7876 ADAMS

                           AAAMfPAAEAAAAAgAAL       7900 JAMES

                           AAAMfPAAEAAAAAgAAM       7902 FORD

                           AAAMfPAAEAAAAAgAAN       7934 MILLER

                           已选择14行。

 

表信息的增删改

        alter table t1 add myname varchar2(20);                         

        alter table t1 modify myname varchar2(40);                             

        alter table t1 drop column myname

 

--删除表(Oracle回收站)

drop table test1;

--oracle的回收站

        -- 查看回收站        show recyclebin

        -- 清空回收站        purge recyclebin;

        -- 彻底删除一张表

        drop table test1 purge; --直接删除一张表,不通过回收站

        -- 还原表(从回收站中返复原表)

                  闪回的内容

        --关于回收站注意问题

        --并不是所有的人都有回收站管理员没有回收站   

 

        SQL> show recyclebin;

        ORIGINAL NAME    RECYCLEBIN NAME               OBJECT TYPE  DROP TIME

        ---------------- ------------------------------ ------------ -------------------

        EMP20            BIN$yB56S7m9QCacFW9wbkk4Ig==$0 TABLE       2014-08-10:22:48:43

        SQL> select * from emp20;  不可以访问表

        SQL> select * from BIN$yB56S7m9QCacFW9wbkk4Ig==$0         不可以访问表

        SQL> select * from "BIN$yB56S7m9QCacFW9wbkk4Ig==$0";       可以访问表

        结论:通过回收站的名字,查看原来表的内容,需要双引号

        

        SQL> select * from tab;

                                    TNAME                          TABTYPE CLUSTERID

                                    ------------------------------ ------- ----------

                                    DEPT                           TABLE

                                    EMP                            TABLE

                                    BONUS                          TABLE

                                    SALGRADE                       TABLE

                                    EMP10                          TABLE

                                    BIN$fzmdJXyITtOZOnFngV2ONQ==$0 TABLE   =====>回收站

                                    T2                             TABLE

                                    TESTDELETE                     TABLE

                                    T1                             TABLE

                                    T3                             TABLE

                                    T5                             TABLE

                                    EMPINCOMEVIEW                  VIEW

                                    HREMP                          SYNONYM

                                    

                                    已选择13行。

5集合运算

集合运算

讲集合运算,实质上是讲集合运算的操作符

 

--查询部门号是10 20的员工信息

        

方法1

        select * from emp where deptno in (10, 20);

 

方法2

        select * from emp where deptno=10 or deptno=20;

 

方法3

        select * from emp where deptno = 10

        union

        select * from emp where deptno = 20;

 

集合运算注意问题:      参与运算各个集合必须列数相同,且类型一致

                           采用第一个集合的表头作为最后的表头

                           必须在每一个集合后使用相同的order by

                           使用括号

 

5.创建表,使用alter进行表信息的增删改,Oracle回收站,集合运算