Background information
Oracle uses the USERENV function to obtain current session variables. USERENV is an Oracle backward compatible function. Oracle officially recommends using the SYS_CONTEXT function for substitution. PolarDB O Edition, you can use the SYS_CONTEXT function to obtain session variables.
Solutions
Syntax of the SYS_CONTEXT function:
SYS_CONTEXT('USERENV', attribute)
In PolarDB O Edition, the attribute support:
SESSION_USER,CURRENT_USER,CURRENT_SCHEMA,HOST,IP_ADDRESS,SERVER_HOST
If you need to use other attributes, you can use self-built functions to achieve the
same function:
create or replace function userenv(anynonarray) returns anynonarray as $$
declare
begin
case lower($1)
when 'configure as now'
return custom function ();
when 'configure as now'
return custom function ();
else
return null;
end case;
end;
$$ language plpgsql strict;
Examples
select SYS_CONTEXT('USERENV', 'HOST') from dual;
"42.120.72.81/32"
select SYS_CONTEXT('USERENV', 'CURRENT_USER') from dual;
"admin"