You need to enable JavaScript to run this app.
文档中心
云数据库 PostgreSQL 版

云数据库 PostgreSQL 版

复制全文
下载 pdf
插件
兼容性扩展(orafce)
复制全文
下载 pdf
兼容性扩展(orafce)
orafce 是一个 PostgreSQL 扩展插件,旨在提供与 Oracle 数据库兼容的功能,包括部分语法、数据类型、函数和字典表等。这使得使用 Oracle 数据的应用程序能够更方便地迁移到 PostgreSQL 中,从而减少应用程序代码的改动量,简化迁移过程。​
创建与删除插件​
  • 创建插件​
说明​
需使用高权限账号创建插件。​
  • ​
    create extension orafce;​
    ​
  • 删除插件​
  • ​
    drop extension orafce;​
    ​
使用插件​
​
--字符串处理:​
postgres=# SELECT oracle.INSTR('Hello World', 'World') AS position; -- 返回 7​
position ​
----------​
7​
(1 row)​
​
postgres=# SELECT oracle.SUBSTR('Hello World', 1, 5) AS substring; -- 返回 'Hello'​
substring ​
-----------​
Hello​
(1 row)​
​
​
--日期处理:​
postgres=# SELECT oracle.ADD_MONTHS(NOW(), 1) AS next_month; -- 返回下个月的同一天​
next_month ​
---------------------​
2024-09-16 17:21:24​
(1 row)​
​
postgres=# SELECT oracle.LAST_DAY(NOW()) AS last_day_of_month; -- 返回本月最后一天​
last_day_of_month ​
---------------------​
2024-08-31 17:21:24​
(1 row)​
​
--数学函数:​
postgres=# SELECT oracle.ROUND(123.456, 2) AS rounded_value; -- 返回 123.46​
rounded_value ​
---------------​
123.46​
(1 row)​
​
postgres=# SELECT oracle.TRUNC(123.456, 2) AS truncated_value; -- 返回 123.45​
truncated_value ​
-----------------​
123.45​
(1 row)​
​
--条件表达式:使用 NVL 函数来处理空值:​
postgres=# SELECT oracle.NVL(NULL::text, '默认值') AS result; -- 返回 '默认值'​
result ​
--------​
默认值​
(1 row)​
​
postgres=# select oracle.nvl(NULL::int, 2);​
nvl ​
-----​
2​
(1 row)​
​
--正则表达式:​
postgres=# SELECT oracle.REGEXP_LIKE('abc123', '^[a-zA-Z]+[0-9]+$') AS is_match; -- 返回 true​
is_match ​
----------​
t​
(1 row)​
​
postgres=# SELECT oracle.REGEXP_INSTR('123 123456 1234567, 1234567 1234567 12', '[^ ]+', 1, 6) ;​
regexp_instr ​
--------------​
37​
(1 row)​
​
​
-- DBMS_UTILITY包​
postgres=# DO $$​
postgres$# DECLARE​
postgres$# start_time integer;​
postgres$# end_time integer;​
postgres$# BEGIN​
postgres$# start_time := DBMS_UTILITY.GET_TIME();​
postgres$# PERFORM pg_sleep(2);​
postgres$# end_time := DBMS_UTILITY.GET_TIME();​
postgres$# -- clamp long runtime on slow build machines to the 2s the testsuite is expecting​
postgres$# IF end_time BETWEEN start_time + 300 AND start_time + 1000 THEN end_time := start_time + 250; END IF;​
postgres$# RAISE NOTICE 'Execution time: % seconds', trunc((end_time - start_time)::numeric/100);​
postgres$# END​
postgres$# $$;​
NOTICE: Execution time: 2 seconds​
DO​
postgres=# ​
​
-- dbms_random包​
postgres=# SELECT dbms_random.initialize(8);​
initialize ​
------------​
​
(1 row)​
​
postgres=# SELECT dbms_random.normal()::numeric(10, 8);​
normal ​
-------------​
-0.37787769​
(1 row)​
​
postgres=# SELECT dbms_random.normal()::numeric(10, 8);​
normal ​
------------​
0.80499804​
(1 row)​
​
postgres=# SELECT dbms_random.seed(8);​
seed ​
------​
​
(1 row)​
​
postgres=# SELECT dbms_random.random();​
random ​
------------​
-632387854​
(1 row)​
​
​
--DBMS_OUTPUT包​
postgres=# CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$​
postgres$# DECLARE​
postgres$# buff1 VARCHAR(20) := 'orafce';​
postgres$# BEGIN​
postgres$# PERFORM DBMS_OUTPUT.DISABLE();​
postgres$# PERFORM DBMS_OUTPUT.ENABLE();​
postgres$# PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t');​
postgres$# PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE');​
postgres$# PERFORM DBMS_OUTPUT.PUT_LINE (buff1);​
postgres$# PERFORM DBMS_OUTPUT.PUT ('ABC');​
postgres$# PERFORM DBMS_OUTPUT.PUT_LINE ('');​
postgres$# END;​
postgres$# $$ LANGUAGE plpgsql;​
CREATE FUNCTION​
postgres=# SELECT dbms_output_test();​
ORAFCE​
orafce​
ABC​
dbms_output_test ​
------------------​
​
(1 row)​
​
其他​
更多信息,请参见 orafce 官方文档。​
​
最近更新时间:2026.01.12 20:03:58
这个页面对您有帮助吗?
有用
有用
无用
无用