PL/SQL-判断一个表是否存在

PL/SQL-判断一个表是否存在

存在时删除重建,不存在时直接创建,执行内容可以根据情况修改。

DECLARE
   table_yn   NUMBER;

BEGIN
   SELECT COUNT (*)  INTO table_yn
     FROM user_tables
    WHERE table_name = UPPER ('test_table');

   IF table_yn > 0
   THEN
      EXECUTE IMMEDIATE 'drop  table test_table cascade  constraints';
      DBMS_OUTPUT.put_line ('The table sugon_calibrate_io has been  deleted');
   END IF;

   EXECUTE IMMEDIATE 'CREATE TABLE test_table (start_time DATE,
   end_time DATE, Max_IOPS NUMBER, Max_MBPS NUMBER, Latency NUMBER)';
   DBMS_OUTPUT.put_line ('The table sugon_calibrate_io has been  created');

END;
/

 

你可能感兴趣的:(操作技巧)