[b]判断表是否存在当前数据库中[/b]
--创建一个函数
create or replace function Fun_Is_Exists_Table(i_table_name in varchar2) return number is
o_result number;
begin
declare
num number;
begin
select count(1) into num from user_tables where table_name = upper(i_table_name) or table_name = lower(i_table_name);
if num > 0 then
o_result := 1;
end if;
if num <= 0 then
o_result := 0;
end if;
end;
return o_result;
end Fun_Is_Exists_Table;
/
--创建存储过程调用函数
create or replace procedure Is_Exists_Table
(
i_table_name in varchar2
)
as
begin
declare num number;
begin
num := Fun_Is_Exists_Table(i_table_name);
if num > 0 then
dbms_output.put_line('表-->> ' || upper(i_table_name) || ' <<--已存在');
end if;
if num <= 0 then
dbms_output.put_line('表-->> ' || upper(i_table_name) || ' <<--不存在');
end if;
end;
end Is_Exists_Table;
/
--调用存储过程
--在控制台输出
set serveroutput on;
exec Is_Exists_Table('tablename');
--创建一个函数
create or replace function Fun_Is_Exists_Table(i_table_name in varchar2) return number is
o_result number;
begin
declare
num number;
begin
select count(1) into num from user_tables where table_name = upper(i_table_name) or table_name = lower(i_table_name);
if num > 0 then
o_result := 1;
end if;
if num <= 0 then
o_result := 0;
end if;
end;
return o_result;
end Fun_Is_Exists_Table;
/
--创建存储过程调用函数
create or replace procedure Is_Exists_Table
(
i_table_name in varchar2
)
as
begin
declare num number;
begin
num := Fun_Is_Exists_Table(i_table_name);
if num > 0 then
dbms_output.put_line('表-->> ' || upper(i_table_name) || ' <<--已存在');
end if;
if num <= 0 then
dbms_output.put_line('表-->> ' || upper(i_table_name) || ' <<--不存在');
end if;
end;
end Is_Exists_Table;
/
--调用存储过程
--在控制台输出
set serveroutput on;
exec Is_Exists_Table('tablename');