用oracle存储过程创建表

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

create or replace procedure createtable(tname in varchar2)
is
SQLTEXT varchar2(400);
v_createsql varchar2(400);
v_dropsql varchar2(100);
v_count number(9);
begin

SQLTEXT := 'grant create any table to newsname'; --newsname为数据库用户名,这里需要给他创建表的权限
EXECUTE IMMEDIATE SQLTEXT;
v_createsql:='create table '||tname||'(
a number(8) primary key,
b varchar2(20))';
v_dropsql:='drop table '||tname||' cascade constraints';
select count(*) into v_count from user_tables where table_name=upper(tname);
if v_count>0 then
execute immediate v_dropsql;
commit;
end if;

execute immediate v_createsql;
commit;
end;















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 ;

相关文档
最新文档