oracle 基础

-- Create table

create table tableName
(
  id  NUMBER(20),
  name  VARCHAR2(100),
);
-- Add comments to the table 
comment on table  tableName
  is '表名';
-- Add comments to the columns 
comment on column     tableName.id

is '主键ID';

comment on column  tableName.name

 is '姓名';


--  drop table

drop table tableName;


-- add column  
alter table   tableName  add (sex  varchar2(30), age  number(3));
-- Add comments to the columns
comment on column tableName.sex
is '性别';
comment on column tableName.age
is '年龄';
/

-- delete column

alter table tableName   drop column sex;

alter table tableName   drop column age;



-- update column length unit

在表中有数据的情况下


--1、对  tableName  进行备份

    create table tableName_bak as select * from  tt_waybill;

--2、删除 tt_waybill 表内的数据
    delete  from  tableName;

--3、修改tt_waybill 字段
alter   table   tableName  modify   sex  varchar2(1);
alter   table   tableName  modify   age  number(2);

--4、还原表结构
   insert into tableName  select * from tableName _bak;
   commit;

-- update column  name

alter   table  tableName rename column sex  to new_sex ;


-- CRUD

insert into tableName  values ( ' 1 ','翠花','女', '18');

delete * from tableName where name='翠花';

delete from tableName  --删除重复数据

 where id in (select id
                from (select tmn.*,
                             row_number() OVER(PARTITION BY age order by id) ord
                        from  tableName  tmn)
               where ord > 1);

select * from  tableName ;

select *  from tableName  where   create_tm > date'2016-10-19' + 0/24    and tmw.create_tm < date'2016-10-20' + 0/24  ; 查询20号一天的数据

update tableName set name=' 小花' where name='翠花';

update tableName    set  name = '蒋' ||  name    where length(name) = 2; --name的字段长度等于2,就在 前面


--create  sequence 
create sequence sel_name
minvalue 1 
maxvalue 999999999999999999999999999 
start with 1 
increment by 1 
cache 20 order;


--drop sequence 

drop sequence sql_name;







评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值