oracle数据库操作总结,主要讲解了oracle92的服务,监听器,建库,表,常用函数...总结,是初学者的入门必备!
r(20) not nlll,
*
ERROR 位于第 4 行:
ORA-00907: 缺少右括号
SQL> CREATE TABLE master(
2 id number(11,0) primary key,
3 loginid nvarchar2(50) not null,
4 password nvarchar2(20) not nlll,
5 status char(1) default 1 not null);
password nvarchar2(20) not nlll,
*
ERROR 位于第 4 行:
ORA-00905: 缺少关键字
SQL> CREATE TABLE master(
2 id number(11,0) primary key,
3 loginid nvarchar2(50) not null,
4 password nvarchar2(20) not null,
5 status char(1) default 1 not null);
表已创建。
SQL> create table type(
2 id number(11) not null,
3 name nvarchar2(50) not null,
4 status char(1) default 1 not null);
表已创建。
SQL> )alter table type Add constraint type_pk primary key(id);
SP2-0734: 未知的命令开头 ")alter tab..." - 忽略了剩余的行。--设置主键
SQL> ALTER TABLE type Add constraint type_pk primary key(id);
表已更改。
SQL> CREATE TABLE pet(
id number(11),
master_id number(11) not null,
name NVARCHAR2(50),
type_id NUMBER(11) NOT NULL,
health number(11) default 100 not null,
love number(11) default 100 not null,
adopt_time date not null,
status char(1) default 1 not null,
constraint pet_pk primary key(id),
constraint master_fk foreign key (master_id) references master(id),
constraint type_fk foreign key (type_id) references type(id)
);
表已创建。
SQL> drop table;
drop table
*
ERROR 位于第 1 行:
ORA-00903: 表名无效
SQL> drop table pet;
表已丢弃。重新创建
SQL> --创建注释,分别给表和表中列;
SQL> COMMENT ON TABLE pet IS '宠物';
SQL> COMMENT ON column http://www.77cn.com.cn IS '宠物昵称';
同样我们也可以在Oracle的图像界面进行数据表的创建
注意:查询的时候表面要加双引号
eg:select * from "user"
--如何实现主键自增长?
--Oracle 中的Create sequence命令用于创建序列
create sequence seq_name
[START with start] --起始值
[INCREMENT BY increment] --增长量,如果死负数则为递减序列
[minvalue minvalue|nominvalue]--是否有最小值
[maxvalue maxvalue|nomaxvalue]--是否有最大值
[cycle|nocycle] --用来指明序列达到最大值或者最小值后
[cache cache|nocache] --用来指明是否在缓存中保存预分配的序列值。如果选中保存可以提高序列值的速度
[order|noorder] --选项保证序列值的唯一性和顺序性,noorder只能保证序列值的唯一性
例如:
create sequence master_seq
start with 1
increment by 1
nomaxva
lue
cache 10;
--使用序列时,需要用到序列的两个伪列nextval和currval。前者返回序列的下一个值,后者返回当前值
--可以通过alter sequence语句对序列进行修改,如果修改序列的起始值,则必须先删除序列,再重新创建
eg:
alter seq