In Oracle PL/SQL is there any way to import packages and their members?

。_饼干妹妹 提交于 2019-12-07 03:01:00

问题


Given a package:

create or replace package foo as
  f1 number := 1;
end;
/

Instead of:

declare
begin
  dbms_output.put_line('f1 = ' || foo.f1);
end;
/

I'd like to write:

declare
begin
  -- pseudocode not a valid PL/SQL
  import dbms_output.*;
  import foo.*;
  put_line('f1 = ' || f1);
end;
/

But how to do that ?

EDIT by Jeff: (trying to stay in the spirit of how things are done in PL/SQL)

DECLARE
  PRAGMA IMPORT dbms_output AS d;
  PRAGMA IMPORT foo AS f;
BEGIN
  d.put_line('f1 = ' || f.f1);
END;
/

回答1:


Quite simply, you can't. Sorry, but there is no other answer!




回答2:


Of course you can!

:) sort of...

declare
  procedure put_line (p in varchar2) is begin dbms_output.put_line(p); end;
  function f1 return number is begin return foo.f1; end;
begin
   put_line('f1 = ' || f1);
end;
/


来源:https://stackoverflow.com/questions/5650319/in-oracle-pl-sql-is-there-any-way-to-import-packages-and-their-members

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!