Thread: Oracle to PostgreSQL: Packages

Oracle to PostgreSQL: Packages

From
"Mark Wilson"
Date:
In oracle you can have private variables within your package, e.g.
create or replace package examplepackage as
  procedure p_set_var(val varchar2);
  pragma restrict_references(p_set_var, rnps, rnds, wnds);
  function f_get_var return varchar2;
  pragma restrict_references(f_get_var, wnps, rnds, wnds);
end examplepackage;
/
show errors;

create or replace package body examplepackage as
  privatevar varchar2(32);
  procedure p_set_var(
    val varchar2
  ) AS
  begin
    privatevar := val;
  end;
  function f_get_var return varchar2 AS
  begin
    return privatevar;
  end;
end examplepackage;
/
show errors;

execute examplepackage.p_set_var('a');
select examplepackage.f_get_var from dual;


This allows you to effectively use session or transaction variables within your code. Is there a way to emulate this in PostgreSQL?