Oracle的DDL、DML

1.Oracle体系结构:

数据库 —> 数据库实例ORCL —> 表空间 (用户里面的创建表) —> 数据文件
地球 —> 中国 —> 省份 (人民) —> 土地山川河流

  • 创建表空间: 逻辑单位, 通常我们新建一个项目,就会去新建表空间,在表空间中创建用户来创建表
语法:
    create tablespace 表空间的名称
    datafile '文件的路径(服务器上)'
    size 大小
    autoextend on  自动扩展
    next 每次扩展的大小
  • 例如:
--切换到system帐号下创建
--创建一个表空间 --- 汉东
create tablespace handong
datafile 'c:\handong.dbf'
size 100m
autoextend on
next 10m;

--删除表空间
drop tablespace handong;
2.创建用户
 create user 用户名
 identified by 密码
 default tablespace 表空间的名称
    例如
    create user dakang
    identified by dakang
    default tablespace handong;
3.授权

grant 角色 | 权限 to 用户

--授予连接权限
grant connect to dakang;
--授予 dba的角色
grant dba to dakang;
4.表的创建
创建表:
    create table 表名(
      列名  列的类型 [列的约束],
      列名  列的类型  [列的约束]      
    );
 列的类型:
    varchar ,在Oracle中,目前是支持的, 但是不保证以后还支持
    
    varchar2(长度) 可变字符长度    varchar2(10)  hello  占5个字符
    char(长度)   固定长度字符      char(10)      hello  占10个字符,用空格填充
    number(总长度,小数长度)     数字类型 --小数长度不能大于等于总长度
    
    date                   年月日时分秒 2017/4/13 9:43:49
    timestamp              时间戳, 比date类型更加精确 13-APR-17 09.44.08.272000 AM +08:00
    
    LONG/CLOB : 存放一本小说
    BLOB      : 存放电影  java 存进去,  再读取出来
create table test1(
   name1 varchar2(10),
   name2 char(10),
   age   number(2,3)    
);
insert into test1(name1,name2) values('hello','hello');
select * from test1 where name1 like 'hello'; --可以查询数据
select * from test1 where name2 like 'hello'; --查不出数据

insert into test1(age) values(2);
select current_date from dual;
select current_timestamp from dual;
使用子查询的方式创建表
create table 表名 as 查询语句; 
注意: 只会复制表结构和表中的数据,不会复制列的约束     
      如果查询语句有结果, 就是复制 表结构和数据
      如果查询语句没有结果, 就是复制 表结构   
--  create table 表名 as 查询语句; 复制表     
select * from scott.emp;

create table emp as select * from scott.emp;

--如果查询语句是没有任何的结果的
select * from scott.emp where 1=2;
--这个有结果
create table emp1 as select * from scott.emp where 1=2;
5.修改表:
  • 添加列
  • 修改列 vharchar2(10)
  • 删除列
  • 修改列名
  • 重命名表
SQL分类:

DDL : 数据定义语言, 修改的结构 alter create drop truncate
DML : 数据操纵语言 , 操作表中数据 insert update delete
DCL : 数据控制语言 , grant
DQL : select

create table stu(
    stuid number,
    sname varchar(10)   
);

添加一列

alter table stu add phone varchar2(11);

alter table stu add (
   mobile varchar2(11),
   s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值