Search notes:

SQLPATH - drop_if_exists

drop_if_exists.sql is an SQL script to be run in SQL*Plus to drop an object (not only a table) if the object exists.
The script is run like so. Note that the object type is not specified:
@drop_if_exists sales_2018

Script

set verify off
declare
--
--    TODO: Synonyms can have the same name as a table, view, package etc.
--
--    To drop a user/schema, use
--       drop_schema_if_exists.sql
--

  obj_name  varchar2(30) := '&1';
  obj_owner varchar2(30);
  obj_type  varchar2(30);

begin

  select owner, object_type into obj_owner, obj_type
    from (
      select owner, object_type,
             row_number() over (order by case when owner = user then 1 else 2 end) r
        from all_objects
       where object_name = upper(obj_name) and
             object_type not like '% BODY'
    )
    where r = 1;

  execute immediate
    'drop ' || obj_type || ' ' || obj_name || case when obj_type = 'TABLE' then ' purge' end;

exception
   when no_data_found then
        null;

   when others then
        dbms_output.put_line(obj_name || ' caused ' || sqlerrm);

end;
/
Github repository Oracle-SQLPATH, path: /drop_if_exists.sql

See also

The SQL verb drop
The create … if not exists and drop … if exists clause in Oracle 23c.
Oracle: files for ORACLE_PATH / SQLPATH

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758198440, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL-Plus/sqlpath/drop_if_exists(89): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78