Oracle存储过程---创建、删除表

时间:2024-05-19 18:24:10

–创建表 参数:表名,建表语句
CREATE OR REPLACE PROCEDURE TRYADDTABLE (tableName IN varchar2,createTableSql IN varchar2)
authid current_user
is
row1 number;
begin
select count(table_name)
into row1
from user_tables
where table_name = upper(tableName);
IF (row1 <= 0) THEN
execute immediate createTableSql;
END IF;
END;

– 调用方式如下:
Oracle存储过程---创建、删除表
– 调用存储过程删表 参数:表名
CREATE OR REPLACE PROCEDURE tryDropTable(tableName IN varchar2) is
stmt VARCHAR2(2000);
row1 number;
begin
select count(table_name) into row1 from user_tables where table_name=upper(tableName);
IF (row1>0) THEN
stmt :='DROP TABLE '|| tableName;
execute immediate stmt;
END IF;
END tryDropTable;
– 调用示例
CALL TRYDROPTABLE(‘T_CAXT_CCSYXF’);