如何在 Oracle 中删除多个函数

Afi*_*han 1 sql database oracle plsql oracle-sqldeveloper

我想在 Oracle 的 SQL 开发人员中一次从我的数据库中删除多个函数。有没有人知道如何为此创建脚本?

Lit*_*oot 5

好吧,您必须知道要放弃哪些。我在IN随后的脚本的子句中将它们全部命名。

先测试功能:

SQL> create or replace function f1 return number is begin return 1; end;
  2  /

Function created.

SQL> create or replace function f2 return number is begin return 2; end;
  2  /

Function created.
Run Code Online (Sandbox Code Playgroud)

做他们的工作?

SQL> select f1, f2 from dual;

        F1         F2
---------- ----------
         1          2
Run Code Online (Sandbox Code Playgroud)

是的,他们这样做。

让我们将它们放入脚本中:

SQL> begin
  2    for cur_r in (select object_name
  3                  from user_objects
  4                  where object_name in ('F1', 'F2')
  5                    and object_type = 'FUNCTION'
  6                 )
  7    loop
  8      execute immediate 'drop function ' || cur_r.object_name;
  9    end loop;
 10  end;
 11  /

PL/SQL procedure successfully completed.
Run Code Online (Sandbox Code Playgroud)

他们现在工作吗?

SQL> select f1, f2 from dual;
select f1, f2 from dual
           *
ERROR at line 1:
ORA-00904: "F2": invalid identifier


SQL>
Run Code Online (Sandbox Code Playgroud)

不,因为它们被丢弃了。