用oracle儲存過程建立表
阿新 • • 發佈:2019-01-27
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;