oracle PL/SQL 中包的别名或同义词
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19110619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alias or synonym for a package in PL/SQL
提问by Mike
I have a system where I have split my functionality into several different packages. Currently I am calling functions and procedures using the dot notation of packagename.object
我有一个系统,我将我的功能拆分为几个不同的包。目前我正在使用 packagename.object 的点表示法调用函数和过程
Some of my package names (due to company coding standards) are fairly long
我的一些包名(由于公司编码标准)相当长
Can I create an alias/synonym for the package to shorten my code?
我可以为包创建别名/同义词以缩短我的代码吗?
ie: instead of pkge_member_utilities.CreateMember, I could create a synonym/alias 'util' for the package and then use util.CreateMember throughout my code
即:代替 pkge_member_utilities.CreateMember,我可以为包创建一个同义词/别名“util”,然后在整个代码中使用 util.CreateMember
I have read up on the documentation for CREATE SYNONYM but it is confusing as it seems to be used against an execute immediate whereas I want to to reference the synonym in my code
我已经阅读了 CREATE SYNONYM 的文档,但它令人困惑,因为它似乎用于立即执行,而我想在我的代码中引用同义词
Again, apologies for the vague terminology as I'm coming at this from a Java background
再次为含糊的术语道歉,因为我是从 Java 背景而来的
Many thanks for your time
非常感谢您的时间
Mike
麦克风
采纳答案by Michael O'Neill
Although I agree with comments above, that largely this is an effort to defeat standards. However, sometimes standards are horrible, and as long as there are suitable unit tests, in the right situation, what is the harm?
虽然我同意上面的评论,但这在很大程度上是为了打破标准。然而,有时标准是可怕的,只要有合适的单元测试,在正确的情况下,有什么害处?
create or replace package long_package_name as
function give_me_zero return number;
end;
/
create or replace package body long_package_name as
function give_me_zero return number is begin return 0; end;
end;
/
create or replace synonym pkg for long_package_name;
-- either works the same
select long_package_name.give_me_zero from dual;
select pkg.give_me_zero from dual;
回答by Shann
create public synonym util for <owner>.pkge_member_utilities;
create public synonym util for <owner>.pkge_member_utilities;