Oracle学习

1、最近由于项目需要,又开始学习Oracle,本以为他和其他数据没什么区别,但一开始惨痛的经历告诉我,还是要认真对待他的。。

错误1:登陆https://localhost:1158/em 之后,看到数据库实例都是关闭的.启动不了.

办法:进入Net Configuration Assistant把当前的监听程序删除重新配置下就好了,然后在服务中把监听程序启动起来。

 

错误2:Oracle中的自增字段没有SQL Server或者Mysql中那么简单,需要设置序列和触发器什么的。但是又遇到ORA-04089: 无法对 SYS 所有的对象创建触发器

办法:system如果正常登录,它其实就是一个普通的dba用户,但是如果以as sysdba登录,其结果实际上它是作为sys用户登录的,这一点类似Linux里面的sudo的感觉,从登录信息里面我们可以看出来。因此在as sysdba连接数据库后,创建的对象实际上都是生成在sys中的。其他用户也是一样,如果 as sysdba登录,也是作为sys用户登录的。

自增字段设置方法:

 

create table UserInfo
(
       UserID int primary key not null,
       UserName varchar(20) not null,
       Power int not null
);
create sequence UserSequence //创建序列
increment by 1 
start with 1 
nomaxvalue 
nocycle;
create trigger UserSequence before insert on UserInfo for each row  //创建触发器
begin
select UserSequence.nextval into:New.UserID from dual;
end;
insert into UserInfo(UserName,Power) values('123',1);//插入数据。


 



 

posted @ 2013-07-01 19:48  啵啵那个臭  阅读(129)  评论(0编辑  收藏  举报