论坛首页 综合技术论坛

oracle判断表是否存在

浏览 9072 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-02-10   最后修改:2009-02-10
判断表是否存在当前数据库中

--创建一个函数
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');

   发表时间:2009-02-11  
楼主,你这个只能判断当前用户下的表是否存在,对于别的用户授权给你的表就判断不了了。
0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics