oracle 存储过程建表

2025-03-25 17:06:18
推荐回答(1个)
回答(1):

这个过程就行了。。
create or replace procedure wym
authid current_user
is
vn_ctn number(2);
begin
select count(*) into vn_ctn from user_all_tables a where a.table_name like upper('invbasdoc');
if vn_ctn > 0 then
execute immediate 'drop table invbasdoc';
end if;
execute immediate 'create table invbasdoc as select * from test_abcd';
end ;

原来的过程中:execute immediate 'drop table invbasdoc'; 当如果数据库中不存在这张表的时候就会报错的。。
上面是对数据库中是否存在表进行了判断,因此能够避免“表不存在”这样的错误。。