oracle的新建语句

--判断是否有此表
declare
  v_count number;
begin
  select count(*)
    into v_count
    from user_tables t
   where t.TABLE_NAME = 'PERSON'; -- 这里注意表名要大写
  if v_count > 0 then
    execute immediate 'drop table PERSON'; -- 这里表名也要大写
  end if;
end;

/ --pl/sql 有这个才能一起执行
--创建表
create table person (
pid number(11)  primary key,
name     varchar2(50) not null,
age      number(11),
birthday date,
create_time  date
);

--添加表注释:
COMMENT ON table person IS '个人信息';
comment on column person.pid is '主键';
comment on column person.name is '姓名';
comment on column person.age is '年龄';
comment on column person.birthday is '生日';
comment on column person.create_time is '创建时间';


--序列虽然是给某个表使用,但是序列并没有绑定字某一张表,任何一张表使用这个序列都可以
create sequence seqpersonid;

--查询序列的下一个值(重点)
select seqpersonid.nextval from dual;

insert into person
  (pid, name, age,birthday,create_time)
values
  (seqpersonid.nextval, '张三', 18,to_date('2020-02-17','YYYY-MM-DD'),sysdate);
分页查询
--无排序
select t2.*
  from (select t.*, rownum rowno from person  t where rownum <= 10) t2
 where t2.rowno >= 1;

--有排序的
select *
    from (select t2.*, rownum rowno
            from (select t.*
                    from person t
                   order by t.pid desc ,t.create_time  ) t2
           where rownum <= 10) t3
   where t3.rowno >= 1;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值