oracle基本语法

/* 1. 创建一个表空间。 2. 创建一个用户,设置默认表空间。 3. 给用户授权。 4. 用当前用户登录,创建表、视图、存储过程等。 */ create tablespace systemManagerTablespace datafile 'systemManager.dbf' size 50M;

--添加表空间大小 alter tablespace systemManagerTablespace add datafile 'systemManager2.dbf' size 10M;

--drop tablespace systemManagerTablespace

 

--数据字典 --select * from dba_data_files

create user student identified by student123 ;

grant connect to student; grant resource to student;

--创建表 /*

表的结构:数据类型。 数字:int、number(p,s)p总长度、s小数点位数 字符:char、nchar 、 varchar2、nvarchar2 时间:date (当前时间:sysdate)

--大对象lob类型 字符串大对象:clob 二进制大对象:blob */

--索引 /* 1. 一张表,具备主键索引。 2. 需要经常用来检索。(添加索引);数据的重复率比较低时。 3. 索引不是越多越好。(查询快)(增、删、改效率下降)

--索引分类。(聚集索引、非聚集索引) 聚集索引:主键索引 非聚集索引:唯一索引、位图索引

create bitmap index weituweitu on t1(tid) */

 

 

 

--表不会直接删除。放入回收站中。 --清空回收站 --PURGE recyclebin create table t1 (        tid int primary key,        tname varchar2(20)       ) ;

insert into t1 values (1001,'张三')

select * from t1

--删除用户 drop user student cascade

select * from scott.dept select * from scott.emp

--视图:不能存在重复列 create view view_emp_dept as select dname,e.* from scott.dept d,scott.emp e where d.deptno = e.deptno

select * from personInfo

--同义词(私有同义词、公共同义词)——表的别名 create or replace public synonym personInfo for scott.emp

--序列(能够生成一个唯一的整数) create sequence test_demo start with 1 increment by 1 minvalue 1 maxvalue 10 cache 5 cycle;--回滚;minvalue

999,999,999,999,999,999,999,999,999

identity()

select test_demo.nextval from dual;

 

100  101   102 .......   最大值 序列重新来过:minvalue

 

select t2_sequence.nextval from dual;

--序列有两个属性:currval | nextval select t1_sequence.currval from dual --必须先调用nextval

insert into t1 values (t1_sequence.nextval,'张三2')

 

posted @ 2013-01-17 23:39  全力以赴001  阅读(223)  评论(0编辑  收藏  举报