您的位置:首页 > 数据库 > Oracle

oracle基本建表语句练习

2014-05-29 14:02 218 查看
//创建表--学生表

create table student(

id number(9) not null primary key,

name varchar2(40) not null,

age number(9),

classname varchar2(40) not null

)

//增加列

alter table student add address varchar2(40)

alter table student add birthday date not null

//删除列

alter table student drop column address

alter table student drop column classname

//修改列的名称

alter table student modify address addresses varchar2(40)

//插入

insert into student values(1,'mary',19,to_date('01-01-1995','MM-DD-YYYY'));

insert into student values(2,'john',20,to_date('01-01-1994','MM-DD-YYYY'));

insert into student values(3,'tom',21,to_date('01-01-1993','MM-DD-YYYY'));

select * from student

SELECT COUNT(*) FROM STUDENT

//创建序列实现id自增

create sequence stu_seq increment by 1 start with 4 MAXVALUE 99 NOCYCLE NOCACHE

//运用序列实现id自增,序列名.nextval

insert into student values(stu_seq.nextval,'tokea',23,to_date('02-05-1991','MM-DD-YYYY'))

insert into student values(stu_seq.nextval,'joy',25,to_date('02-05-1989','MM-DD-YYYY'))

insert into student values(stu_seq.nextval,'yeak',23,to_date('29-08-1991','MM-DD-YYYY'))

//删除某一行数据

delete from 表名 where id=4

//查询年龄不在19,20之间的学生姓名

select name from student where age not between 19 and 20

//模糊查询,首字母为j的学生姓名

select name from student where name like 'j%'

//oracle实现分页

select ×from(

select t.*,rownum from table1 t where condition)

where rownum>(pagen)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: