Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias or synonym for a package in PL/SQL

Tags:

oracle

plsql

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

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

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

Again, apologies for the vague terminology as I'm coming at this from a Java background

Many thanks for your time

Mike

like image 901
Mike Avatar asked Nov 02 '22 13:11

Mike


1 Answers

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;
like image 186
Michael O'Neill Avatar answered Nov 11 '22 08:11

Michael O'Neill