The list below illustrates how to convert the most popular Oracle built-in functions into PostgreSQL equivalents:
ADD_MONTH($date,$n_month)
is replaced by the expression
$date + $n_month * interval '1 month'
DECODE($exp, $when, $then, ...)
must be replaced by PostgreSQL
expression CASE $exp WHEN $when THEN $then ... END
INSTR($str1, $str2)
can be
replaced by POSITION($str2 in $str1)
.LAST_DAY($date)
must be converted into
(date_trunc('MONTH', cast($date as date)) + INTERVAL '1 MONTH - 1 day')::date
LCASE
must be converted into PostgreSQL equivalent LOWER
LOCATE($str1,$str2)
must be replaced by POSITION($str1 in $str2)
MONTHS_BETWEEN($date2,$date1)
is converted into
12 * extract(year from age($date2::date,$date1::date)) + extract(month from age($date2::date,$date1::date))
NVL($a, replace_with)
can be converted into COALESCE($a, replace_with)
RAND
must be replaced by PostgreSQL equivalent RANDOM
REGEXP_LIKE($string, $pattern)
is converted into
PostgreSQL expression $string LIKE $pattern
SYS_GUID()
can be replaced by uuid_generate_v1()
.
In early versions of PostgreSQL (before v9.4) this function depended on the OSSP UUID library.
In order to get version-independent solution, the following expression may be used:
SELECT md5(random()::text || clock_timestamp()::text)::uuid
UCASE
is converted into UPPER
that is synonym in PostgreSQL
Have questions? Contact us