使用游标删除数据库表
2014-03-11 15:40
253 查看
create or replace procedure PROC_DROPTABLE_BIEE
as
--引用user_tables表中的tableName的类型;
--集合处理方式
type record_type is table of user_tables%rowtype;
record_table record_type;
--表名
tableName user_tables.table_name%type;
mycount number(10);
cursor biee_tables_cur is select t.* from user_tables t where t.TABLE_NAME like '%T_BI_%';
rowdata biee_tables_cur%rowtype;
begin
select count(*) into mycount from user_tables t where t.TABLE_NAME like '%T_BI_%';
--存在数据
if (mycount > 0) then
dbms_output.put_line('共有 ' || mycount || ' 条表名包含 T_BI 的表记录');
open biee_tables_cur;
fetch biee_tables_cur bulk collect into record_table;
close biee_tables_cur;
--for Loop
for record_table in biee_tables_cur
Loop
dbms_output.put_line('for loop:' || record_table.table_name );
end Loop;
--while Loop
open biee_tables_cur;
FETCH biee_tables_cur into rowdata;
while biee_tables_cur%found
Loop
dbms_output.put_line('while loop:' || rowdata.table_name );
fetch biee_tables_cur into rowdata;
end Loop;
close biee_tables_cur;
for i in 1.. record_table.count loop
--获取当前表名
tableName:= record_table(i).TABLE_NAME;
--检查是否存在该表
select count(*) into mycount from user_tables t where t.TABLE_NAME=tableName;
--存在则删除
if (mycount > 0) then
dbms_output.put_line('删除表名为 "' || tableName || '" 的表');
execute immediate 'drop table ' || tableName;
else
dbms_output.put_line('不存在表名为 "' || tableName || '" 的表');
end if;
end loop;
--不存在对应数据
else
dbms_output.put_line('不存在表名包含 T_BI 的表记录');
end if;
end;
as
--引用user_tables表中的tableName的类型;
--集合处理方式
type record_type is table of user_tables%rowtype;
record_table record_type;
--表名
tableName user_tables.table_name%type;
mycount number(10);
cursor biee_tables_cur is select t.* from user_tables t where t.TABLE_NAME like '%T_BI_%';
rowdata biee_tables_cur%rowtype;
begin
select count(*) into mycount from user_tables t where t.TABLE_NAME like '%T_BI_%';
--存在数据
if (mycount > 0) then
dbms_output.put_line('共有 ' || mycount || ' 条表名包含 T_BI 的表记录');
open biee_tables_cur;
fetch biee_tables_cur bulk collect into record_table;
close biee_tables_cur;
--for Loop
for record_table in biee_tables_cur
Loop
dbms_output.put_line('for loop:' || record_table.table_name );
end Loop;
--while Loop
open biee_tables_cur;
FETCH biee_tables_cur into rowdata;
while biee_tables_cur%found
Loop
dbms_output.put_line('while loop:' || rowdata.table_name );
fetch biee_tables_cur into rowdata;
end Loop;
close biee_tables_cur;
for i in 1.. record_table.count loop
--获取当前表名
tableName:= record_table(i).TABLE_NAME;
--检查是否存在该表
select count(*) into mycount from user_tables t where t.TABLE_NAME=tableName;
--存在则删除
if (mycount > 0) then
dbms_output.put_line('删除表名为 "' || tableName || '" 的表');
execute immediate 'drop table ' || tableName;
else
dbms_output.put_line('不存在表名为 "' || tableName || '" 的表');
end if;
end loop;
--不存在对应数据
else
dbms_output.put_line('不存在表名包含 T_BI 的表记录');
end if;
end;
相关文章推荐
- 在数据库中使用外键和级联删除
- 使用SQL删除数据库里面用户创建表
- 勤于思考:游标删除数据库所有表数据
- 使用php批量删除数据库下所有前缀为prefix_的表
- 因为数据库正在使用,所以无法获得对数据库的独占访问权---还原或删除数据库的解决方法
- mysql创建数据库,创建数据库表导入xlsx、txt文本,查询、删除、插入数据语句的使用
- 使用游标批量更新/填充数据库(The Using of Cursor)
- Oracle 10g使用游标更新或删除数据
- Hive创建、删除、修改、使用数据库
- 一个完整的数据库备份创建与删除******使用存储过程
- MSSQL数据库 "无法删除数据库 "***",因为该数据库当前正在使用" 解决方案
- python中操作数据库中游标的使用方法
- 无法删除数据库 "aaa",因为该数据库当前正在使用
- 数据库中游标的使用
- 使用SQL删除数据库里面用户创建表
- 因为数据库正在使用,所以无法获得对数据库的独占访问权---还原或删除数据库的解决方法
- 用游标删除符合条件的表 可以清空该数据库下所有表
- 无法删除数据库 "#Test",因为该数据库当前正在使用
- 使用oradim.exe删除数据库实例的时候出现的小问题
- SQL Server无法删除数据库,因为该数据库当前正在使用的解决办法