All Products
Search
Document Center

PolarDB:polar_utility

Last Updated:Mar 28, 2026

The polar_utility plug-in extends PolarDB for Oracle with additional interval and data-conversion functions. Install it once per database, then call any of its functions directly in SQL.

Install and remove the plug-in

Install the plug-in:

CREATE EXTENSION polar_utility;

Remove the plug-in:

DROP EXTENSION polar_utility;

Function reference

polar_utility provides two groups of functions:

Interval functions — convert an interval value to a numeric day count, then apply a transformation:

FunctionReturnsDescriptionQuick example
to_number(interval)numericDay count as a decimal numberto_number(interval '2.1 day')2.1
trunc(interval)numericDay count, integer part onlytrunc(interval '2.1 day')2
abs(interval)numericAbsolute day countabs(interval '-1 day')1
to_char(interval)textDay count as a stringto_char(interval '2.1 day')'2.1'

Conversion functions — parse or re-encode values:

FunctionReturnsDescriptionQuick example
to_date(numeric, character varying)dateParse a numeric date string using a format maskto_date('20200811','yyyymmddhh24miss')Tue Aug 11 00:00:00 2020
to_date(timestamp without time zone)dateCast a timestamp to a date valueto_date('11-AUG-20 03:16:09.089308'::timestamp)Tue Aug 11 03:16:09.089308 2020
mod(text, text)numericModulo operation on text values (converts to numeric first)mod('10'::text, '2'::text)0
convert(text, text)textRe-encode a string to the specified encodingconvert('RAM is the new disk.', 'utf8')'RAM is the new disk.'

Set up test data

The examples below share a common test table. Run the following statements once to create it:

CREATE TABLE polar_test_interval_func(a interval);

INSERT INTO polar_test_interval_func
VALUES (interval '1.1 hour'),
       (interval '2.1 day'),
       (interval '3.1 month'),
       (interval '4.3 year'),
       (('11-AUG-20 03:16:09.089308'::timestamp - 1) - '11-AUG-20 03:16:09.089308'::timestamp),
       (('11-AUG-20 03:16:09.089308'::timestamp + 3) - '11-AUG-20 03:16:09.089308'::timestamp);

Interval functions

to_number(interval)

Converts an interval value to the equivalent number of days, returned as numeric.

SELECT to_number(a) FROM polar_test_interval_func;

Result:

        to_number
-------------------------
  0.04583333333333333333
      2.1000000000000000
     93.0000000000000000
   1551.0000000000000000
 -1.00000000000000000000
      3.0000000000000000
(6 rows)

trunc(interval)

Converts an interval value to the equivalent number of days, then drops the fractional part and returns the integer portion as numeric.

SELECT trunc(a) FROM polar_test_interval_func;

Result:

 trunc
-------
     0
     2
    93
  1551
    -1
     3
(6 rows)

abs(interval)

Converts an interval value to the equivalent number of days, then returns the absolute value as numeric.

SELECT abs(a) FROM polar_test_interval_func;

Result:

          abs
------------------------
 0.04583333333333333333
     2.1000000000000000
    93.0000000000000000
  1551.0000000000000000
 1.00000000000000000000
     3.0000000000000000
(6 rows)

to_char(interval)

Converts an interval value to the equivalent number of days, then returns that number as a text string.

SELECT to_char(a) FROM polar_test_interval_func;

Result:

         to_char
-------------------------
 0.04583333333333333333
 2.1000000000000000
 93.0000000000000000
 1551.0000000000000000
 -1.00000000000000000000
 3.0000000000000000
(6 rows)

Conversion functions

to_date(numeric, character varying)

Converts a numeric date string to a date value using the specified format mask.

SELECT to_date('20200811','yyyymmddhh24miss');

Result:

         to_date
--------------------------
 Tue Aug 11 00:00:00 2020
(1 row)

to_date(timestamp without time zone)

Accepts a timestamp value and returns a date value.

SELECT to_date('11-AUG-20 03:16:09.089308'::timestamp);

Result:

             to_date
---------------------------------
 Tue Aug 11 03:16:09.089308 2020
(1 row)

mod(text, text)

Performs the modulo operation on two text values. The values are cast to numeric before the calculation.

SELECT mod('10'::text, '2'::text);

Result:

 mod
-----
   0
(1 row)

convert(text, text)

Re-encodes a string to the target encoding specified in the second argument.

SELECT convert('RAM is the new disk.', 'utf8');

Result:

       convert
----------------------
 RAM is the new disk.
(1 row)