易截截图软件、单文件、免安装、纯绿色、仅160KB

北大青鸟oracle学习笔记25

过程中的事务
定义过程p1
create or replace procedure p1
as
begin
insert into student values(5,'xdh','m',sysdate);
rollback;
end;
定义过程p2
create or replace procedure p2
as
begin
update student set stu_sex = 'a' where stu_id = 3;
p1;
end;
执行过程p2

exec p2;
执行完毕发现表中数据没有变更,说明p1中的rollback语句将p2中的update语句也回滚了。
自主事务处理
步骤:

主事务处理启动自主事务处理

主事务处理被暂停

自主事务处理sql操作

中止自主事务处理

恢复主事务处理


pragma autonomous_transaction

用于标记子程序
在p1的as begin当中加入 pragma autonomous_transaction  后执行,发行p2的update语句生效,p1中的事务作为自主事务来处理,不影响主事务。
程序包
相关对象的封装

-程序包规格说明

    声明子程序,不包含实现

create package 包名 is|as 变量声明|类型定义|异常声明|游标声明|函数说明|过程说明

pragma restrict_references(函数名,WNDS[,WNPS][,RNDS][,RNPS])

end [包名];

create or replace package StuPackages

is

  type curRefStudent is REF CURSOR RETURN student%rowtype;

  procedure insertStudent(stuid in student.stu_id%type,stuname in student.stu_name%type,stusex in student.stu_sex%type,studate in student.stu_birthday%type);
Function QueryStudent(stuid in student.stu_id%type) return student%rowtype;
end StuPackages;

-程序包主体

    定义子程序,实现声明部分

create package body 包名 is|as 变量声明|类型定义|异常声明|游标声明|函数定义|过程定义

end [包名];
CREATE OR REPLACE
PACKAGE BODY STUPACKAGES AS
procedure insertStudent(stuid in student.stu_id%type,stuname in student.stu_name%type,stusex in student.stu_sex%type,studate in student.stu_birthday%type) AS
i INTEGER;
Student_Exist EXCEPTION;
BEGIN
select count(*) into i from student where stu_id = stuid;
if i>0 then
raise Student_Exist;
else
insert into student values(stuid,stuname,stusex,studate);
commit;
end if;


相关文档:

【转】 ORACLE 分区表 PARTITION table

ORACLE 分区表 PARTITION table
http://blog.chinaunix.net/u/6889/showart_315897.html
1.1 分区表PARTITION table
在ORACLE里如果遇到特别大的表,可以使用分区的表来改变其应用程序的性能。
1.1.1 分区表的建立:
某公司的每年产生巨大的销售记录,DBA向公司建议每季度的数据放在一个分区内,以下示范的是该公司1 ......

ORACLE 对象的使用

--创建对象类型
create or replace type emp_typ as object (
id number,
name varchar2(30),
sal number,
comm number,
member procedure change_comm(new_comm number),
member function get_info return  varchar2
) ;
--创建对象类型构造函数定义
create or replace type body emp_typ is
member proce ......

Oracle千万条记录插入与查询小结

 
最近做了个项目,实现对存在千万条记录的库表进行插入、查询操作。原以为对数据库的插入、查询是件很容易的事,可不知当数据达到百万甚至千万条级别的时候,这一切似乎变得相当困难。几经折腾,总算完成了任务。
  1、避免使用Hibernate框架
  Hibernate用起来虽然方便,但对于海量数据的操作显得力不从心。 ......

Oracle 11g存在密码过期问题

【原因/触发因素】
确定是由于oracle11g中默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”所导致。
【影响和风险】
影响
密码过期后,业务进程连接数据库异常,影响业务使用。
问题发生频率
数据库密码过期后,业务进程一旦重启会提示连接失败。
【解决方案】
按照如下步骤进行操作:
1、查 ......

在Oracle中设置自动增长列


【实现步骤】
 1. 创建表blog_info, 具有ID和title两个字段, 其中ID将设置为自动增长列;
 2. 创建序列:
    create sequence sq_blog_info
    start with 1
    increment by 1
    nomaxvalue
    nocycle
   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号