--判断是否有此表declare
v_count number;beginselectcount(*)into v_count
from user_tables t
where t.TABLE_NAME ='PERSON';-- 这里注意表名要大写if v_count >0thenexecute immediate 'drop table PERSON';-- 这里表名也要大写endif;end;/--pl/sql 有这个才能一起执行--创建表createtable person (
pid number(11)primarykey,
name varchar2(50)notnull,
age number(11),
birthday date,
create_time date);--添加表注释:COMMENTONtable person IS'个人信息';commentoncolumn person.pid is'主键';commentoncolumn person.name is'姓名';commentoncolumn person.age is'年龄';commentoncolumn person.birthday is'生日';commentoncolumn person.create_time is'创建时间';--序列虽然是给某个表使用,但是序列并没有绑定字某一张表,任何一张表使用这个序列都可以create sequence seqpersonid;--查询序列的下一个值(重点)select seqpersonid.nextval from dual;insertinto 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
orderby t.pid desc,t.create_time ) t2
where rownum <=10) t3
where t3.rowno >=1;