Background information

Oracle officially recommends using the SYS_CONTEXT function to obtain system variables. PolarDB-O, some features of the SYS_CONTEXT function are supported.

Solutions

The following table describes how to use the SYS_CONTEXT function.
SELECT SYS_CONTEXT('USERENV', attribute) FROM dual;
In PolarDB-O, only the following attributes are supported:
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"