--如果存在数据库表的就删除,没有的话 就创建一个
create or replace procedure deleteTable(tableName_temp in varchar2) is
temp_tableCount number(10) := 0; --查询表存在的数
v_ival number(10); --loop的临时值
temp_grantuser varchar2(100);
v_createTableSQL varchar2(500); --创建表的SQL
v_deleteTableSQL varchar2(500); --删除表的SQL
begin
select count(*)
into temp_tableCount
from user_tables
where table_name = upper(tableName_temp);
v_createTableSQL := 'create table ' || tableName_temp ||
'( a number(8) primary key, b varchar2(20))';
--v_createTableSQL := 'create table '||tableName_temp||' as select sysdate as sysdate_temp from dual;';
v_deleteTableSQL :='drop table '||tableName_temp||' cascade constraints';
if temp_tableCount > 0 then
execute immediate v_deleteTableSQL;
dbms_output.put_line('删除表成功'||tableName_temp||'!!');
elsif temp_tableCount = 0 then
select user into temp_grantuser from dual;
--必须要给用户赋予权限才可以执行create
execute immediate 'grant create any table to '|| temp_grantuser;
execute immediate v_createTableSQL;
dbms_output.put_line('创建表'||tableName_temp||'成功!!');
else
dbms_output.put_line('出现异常情况!!');
end if;
--------------------------------循环处理快------------------------------------
--Loop循环
v_ival :=0;
loop
exit when v_ival>3;
--循环体
v_ival := v_ival+1;
dbms_output.put_line('loop循环:'||v_ival);
end loop;
exception
--异常处理代码块
when no_data_found then
dbms_output.put_line('发生系统异常:未找到有效的数据!');
when too_many_rows then
dbms_output.put_line('发生系统异常:查询结果超出预期的一行!');
-- when ex_lesszero then
--DBMS_OUTPUT.put_line('sqlcode : ' ||sqlcode);
-- dbms_output.put_line('发生用户异常:数值不能为负!'||sqlcode||'异常描述:'||sqlerrm);
--when others then --other例如Exception
-- rollback;
-- dbms_output.put_line('发生异常!'||sqlcode||'异常的描述:'||sqlerrm);
end deleteTable;
--select to_char(sysdate+ interval '8' day,'yyyy-MM-dd HH24:MM:ss') from dual;
--查询权限
select * from session_privs
create or replace procedure deleteTable(tableName_temp in varchar2) is
temp_tableCount number(10) := 0; --查询表存在的数
v_ival number(10); --loop的临时值
temp_grantuser varchar2(100);
v_createTableSQL varchar2(500); --创建表的SQL
v_deleteTableSQL varchar2(500); --删除表的SQL
begin
select count(*)
into temp_tableCount
from user_tables
where table_name = upper(tableName_temp);
v_createTableSQL := 'create table ' || tableName_temp ||
'( a number(8) primary key, b varchar2(20))';
--v_createTableSQL := 'create table '||tableName_temp||' as select sysdate as sysdate_temp from dual;';
v_deleteTableSQL :='drop table '||tableName_temp||' cascade constraints';
if temp_tableCount > 0 then
execute immediate v_deleteTableSQL;
dbms_output.put_line('删除表成功'||tableName_temp||'!!');
elsif temp_tableCount = 0 then
select user into temp_grantuser from dual;
--必须要给用户赋予权限才可以执行create
execute immediate 'grant create any table to '|| temp_grantuser;
execute immediate v_createTableSQL;
dbms_output.put_line('创建表'||tableName_temp||'成功!!');
else
dbms_output.put_line('出现异常情况!!');
end if;
--------------------------------循环处理快------------------------------------
--Loop循环
v_ival :=0;
loop
exit when v_ival>3;
--循环体
v_ival := v_ival+1;
dbms_output.put_line('loop循环:'||v_ival);
end loop;
exception
--异常处理代码块
when no_data_found then
dbms_output.put_line('发生系统异常:未找到有效的数据!');
when too_many_rows then
dbms_output.put_line('发生系统异常:查询结果超出预期的一行!');
-- when ex_lesszero then
--DBMS_OUTPUT.put_line('sqlcode : ' ||sqlcode);
-- dbms_output.put_line('发生用户异常:数值不能为负!'||sqlcode||'异常描述:'||sqlerrm);
--when others then --other例如Exception
-- rollback;
-- dbms_output.put_line('发生异常!'||sqlcode||'异常的描述:'||sqlerrm);
end deleteTable;
--select to_char(sysdate+ interval '8' day,'yyyy-MM-dd HH24:MM:ss') from dual;
--查询权限
select * from session_privs