Home > Database > Mysql Tutorial > 测试存储过程的状态对执行的影响

测试存储过程的状态对执行的影响

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:10:46
Original
1178 people have browsed it

测试目的: 测试存储过程的状态对该存储过程运行的影响。 环境准备: 1.创建测试表 test_drop_dep create table test_dep(name varchar2(20));insert into test_dep(name) values(ABC);commit; 2.建立依赖表 test_drop_dep的存储过程 create or replace proc

测试目的:

测试存储过程的状态对该存储过程运行的影响。

环境准备:

1.创建测试表 test_drop_dep

create table test_dep(name varchar2(20));
insert into test_dep(name) values('ABC');
commit;
Copy after login

2.建立依赖表 test_drop_dep的存储过程

create or replace procedure test_drop_dep

as
v_count number;
begin
select count(*) into v_count from test_dep;
dbms_output.put_line('BEFORE SLEEP TIME='||to_char(sysdate,'hh24:mi:ss'));
dbms_lock.sleep(30);
dbms_output.put_line('BEHIND SLEEP TIME='||to_char(sysdate,'hh24:mi:ss'));
dbms_output.put_line('THE ROWCOUNT ='||to_char(v_count));
end;
/
Copy after login

测试用例

测试用例1:

session1执行存储过程,session2删除表test_drop_dep,然后查询存储过程的状态。

session1执行存储过程

execute test_drop_dep;

session2删除表test_drop_dep,然后查询存储过程的状态

drop table test_dep;

select object_name,status from dba_objects where object_name='TEST_DROP_DEP';
OBJECT_NAME STATUS
------------------------------ -------
TEST_DROP_DEP INVALID
Copy after login

测试用例1结论:

存储过程依赖的对象失效(删除)后,该存储过程会立即标记为失效invalid,即使该过程正在执行,已经运行的该存储过程会正常执行完毕。

测试用例2:

session1执行存储过程,session2删除表 test_drop_dep ,创建表test_drop_dep,执行存储过程。

session1执行存储过程

execute test_drop_dep;
/*
SQL> execute test_drop_dep;
BEFORE SLEEP TIME=10:06:47
BEHIND SLEEP TIME=10:07:17
THE ROWCOUNT =1
PL/SQL procedure successfully completed.
*/
Copy after login

session2删除表 test_drop_dep ,创建表test_drop_dep,执行存储过程

drop table test_dep;
select object_name,status from dba_objects where object_name='TEST_DROP_DEP';
create table test_dep(name varchar2(20));
insert into test_dep(name) values('ABC');
commit;
select object_name,status from dba_objects where object_name='TEST_DROP_DEP';
execute test_drop_dep;
select object_name,status from dba_objects where object_name='TEST_DROP_DEP';

/*

SQL> drop table test_dep;
Table dropped.
SQL> select object_name,status from dba_objects where object_name='TEST_DROP_DEP';
OBJECT_NAME STATUS
------------------------------ -------
TEST_DROP_DEP INVALID
SQL> create table test_dep(name varchar2(20));
insert into test_dep(name) values('ABC');
Table created.
SQL> commit;
1 row created.
SQL>
Commit complete.
SQL> select object_name,status from dba_objects where object_name='TEST_DROP_DEP';
OBJECT_NAME STATUS
------------------------------ -------
TEST_DROP_DEP INVALID
SQL> execute test_drop_dep;
select object_name,status from dba_objects where object_name='TEST_DROP_DEP';

BEFORE SLEEP TIME=10:07:17
BEHIND SLEEP TIME=10:07:47
THE ROWCOUNT =1
PL/SQL procedure successfully completed.
SQL>
OBJECT_NAME STATUS
------------------------------ -------
TEST_DROP_DEP VALID

*/
Copy after login

测试用例2结论:

有效的存储过程执行后,会一直执行完毕,而不管当前是否是valid状态;
invalid的存储过程第一运行会执行编译,如果此时有未执行完成的该过程,编译一直处于library cache pin等待,直到所有过程都执行完才能编译执行。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template