(转)PostgreSQL 兼容Oracle - orafce
转自:http://blog.163.com/digoal@126/blog/static/1638770402015112144250486/ PostgreSQL是和Oracle最接近的企业数据库,包括数据类型,功能,架构和语法等几个方面。甚至大多数的日常应用的性能也不会输给Oracle。 但是Oracle有些函数或者包,默认PostgreSQL是没有的,需要安装orafce包来实现这些兼容性。
例如现在orafce已经包含了如下内容。 1. 类型 date, varchar2 and nvarchar2
2. 函数 concat, nvl, nvl2, lnnvl, decode, bitand, nanvl, sinh, cosh, tanh and oracle.substr
3. dual 表
4. package :
dbms_output
utl_file
dbms_pipe
dbms_alert
PLVdate
PLVstr and PLVchr
PLVsubst
DBMS_utility
PLVlex
DBMS_ASSERT
PLUnit
DBMS_random orafce的安装步骤如下:
http://pgxn.org/dist/orafce/ 下载最新版本。
wget http://api.pgxn.org/dist/orafce/3.1.2/orafce-3.1.2.zip 安装
unzip orafce-3.1.2.zip
mv orafce-3.1.2 /opt/soft_bak/postgresql-9.4.5/contrib
cd /opt/soft_bak/postgresql-9.4.5/contrib/orafce-3.1.2 把pg_config命令放到当前路径,之后就可以编译安装。
export PATH=/opt/pgsql/bin:$PATH
make clean
make
make install 创建extension 。
su - postgres
psql
postgres=# create extension orafce;
CREATE EXTENSION Oracle兼容 函数列表:
postgres=# \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+---------------------+-----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------
public | bitand | bigint | bigint, bigint | normal
public | cosh | double precision | double precision | normal
public | decode | bigint | anyelement, anyelement, bigint | normal
public | decode | bigint | anyelement, anyelement, bigint, anyelement, bigint | normal
public | decode | bigint | anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint | normal
public | decode | bigint | anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint | normal
public | decode | bigint | anyelement, anyelement, bigint, anyelement, bigint, bigint | normal
public | decode | bigint | anyelement, anyelement, bigint, bigint | normal
public | decode | character | anyelement, anyelement, character | normal
public | decode | character | anyelement, anyelement, character, anyelement, character | normal
public | decode | character | anyelement, anyelement, character, anyelement, character, anyelement, character | normal
public | decode | character | anyelement, anyelement, character, anyelement, character, anyelement, character, character | normal
public | decode | character | anyelement, anyelement, character, anyelement, character, character | normal
public | decode | character | anyelement, anyelement, character, character | normal
public | decode | date | anyelement, anyelement, date | normal
public | decode | date | anyelement, anyelement, date, anyelement, date | normal
public | decode | date | anyelement, anyelement, date, anyelement, date, anyelement, date | normal
public | decode | date | anyelement, anyelement, date, anyelement, date, anyelement, date, date | normal
public | decode | date | anyelement, anyelement, date, anyelement, date, date | normal
public | decode | date | anyelement, anyelement, date, date | normal
public | decode | integer | anyelement, anyelement, integer | normal
public | decode | integer | anyelement, anyelement, integer, anyelement, integer | normal
public | decode | integer | anyelement, anyelement, integer, anyelement, integer, anyelement, integer | normal
public | decode | integer | anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer | normal
public | decode | integer | anyelement, anyelement, integer, anyelement, integer, integer | normal
public | decode | integer | anyelement, anyelement, integer, integer | normal
public | decode | numeric | anyelement, anyelement, numeric | normal
public | decode | numeric | anyelement, anyelement, numeric, anyelement, numeric | normal
public | decode | numeric | anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric | normal
public | decode | numeric | anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric | normal
public | decode | numeric | anyelement, anyelement, numeric, anyelement, numeric, numeric | normal
public | decode | numeric | anyelement, anyelement, numeric, numeric | normal
public | decode | text | anyelement, anyelement, text | normal
public | decode | text | anyelement, anyelement, text, anyelement, text | normal
public | decode | text | anyelement, anyelement, text, anyelement, text, anyelement, text | normal
public | decode | text | anyelement, anyelement, text, anyelement, text, anyelement, text, text | normal
public | decode | text | anyelement, anyelement, text, anyelement, text, text | normal
public | decode | text | anyelement, anyelement, text, text | normal
public | decode | time without time zone | anyelement, anyelement, time without time zone | normal
public | decode | time without time zone | anyelement, anyelement, time without time zone, anyelement, time without time zone | normal
public | decode | time without time zone | anyelement, anyelement, time without time zone, anyelement, time without time zone, anyelement, time without time zone | normal
public | decode | time without time zone | anyelement, anyelement, time without time zone, anyelement, time without time zone, anyelement, time without time zone, time without time zone | normal
public | decode | time without time zone | anyelement, anyelement, time without time zone, anyelement, time without time zone, time without time zone | normal
public | decode | time without time zone | anyelement, anyelement, time without time zone, time without time zone | normal
public | decode | timestamp with time zone | anyelement, anyelement, timestamp with time zone | normal
public | decode | timestamp with time zone | anyelement, anyelement, timestamp with time zone, anyelement, timestamp with time zone | normal
public | decode | timestamp with time zone | anyelement, anyelement, timestamp with time zone, anyelement, timestamp with time zone, anyelement, timestamp with time zone | normal
public | decode | timestamp with time zone | anyelement, anyelement, timestamp with time zone, anyelement, timestamp with time zone, anyelement, timestamp with time zone, timestamp with time zone | normal
public | decode | timestamp with time zone | anyelement, anyelement, timestamp with time zone, anyelement, timestamp with time zone, timestamp with time zone | normal
public | decode | timestamp with time zone | anyelement, anyelement, timestamp with time zone, timestamp with time zone | normal
public | decode | timestamp without time zone | anyelement, anyelement, timestamp without time zone | normal
public | decode | timestamp without time zone | anyelement, anyelement, timestamp without time zone, anyelement, timestamp without time zone | normal
public | decode | timestamp without time zone | anyelement, anyelement, timestamp without time zone, anyelement, timestamp without time zone, anyelement, timestamp without time zone | normal
public | decode | timestamp without time zone | anyelement, anyelement, timestamp without time zone, anyelement, timestamp without time zone, anyelement, timestamp without time zone, timestamp without time zone | normal
public | decode | timestamp without time zone | anyelement, anyelement, timestamp without time zone, anyelement, timestamp without time zone, timestamp without time zone | normal
public | decode | timestamp without time zone | anyelement, anyelement, timestamp without time zone, timestamp without time zone | normal
public | dump | character varying | "any" | normal
public | dump | character varying | "any", integer | normal
public | dump | character varying | text | normal
public | dump | character varying | text, integer | normal
public | nanvl | double precision | double precision, character varying | normal
public | nanvl | double precision | double precision, double precision | normal
public | nanvl | numeric | numeric, character varying | normal
public | nanvl | numeric | numeric, numeric | normal
public | nanvl | real | real, character varying | normal
public | nanvl | real | real, real | normal
public | nvarchar2 | nvarchar2 | nvarchar2, integer, boolean | normal
public | nvarchar2_transform | internal | internal | normal
public | nvarchar2in | nvarchar2 | cstring, oid, integer | normal
public | nvarchar2out | cstring | nvarchar2 | normal
public | nvarchar2recv | nvarchar2 | internal, oid, integer | normal
public | nvarchar2send | bytea | nvarchar2 | normal
public | nvarchar2typmodin | integer | cstring[] | normal
public | nvarchar2typmodout | cstring | integer | normal
public | nvl | anyelement | anyelement, anyelement | normal
public | nvl2 | anyelement | anyelement, anyelement, anyelement | normal
public | sinh | double precision | double precision | normal
public | tanh | double precision | double precision | normal
public | to_multi_byte | text | str text | normal
public | to_single_byte | text | str text | normal
public | varchar2 | varchar2 | varchar2, integer, boolean | normal
public | varchar2_transform | internal | internal | normal
public | varchar2in | varchar2 | cstring, oid, integer | normal
public | varchar2out | cstring | varchar2 | normal
public | varchar2recv | varchar2 | internal, oid, integer | normal
public | varchar2send | bytea | varchar2 | normal
public | varchar2typmodin | integer | cstring[] | normal
public | varchar2typmodout | cstring | integer | normal
(88 rows) Oracle兼容 dual表,在PG里用了一个视图来实现。
postgres=# \dv
List of relations
Schema | Name | Type | Owner
--------+------+------+----------
public | dual | view | postgres
(1 row)
postgres=# \d+ dual
View "public.dual"
Column | Type | Modifiers | Storage | Description
--------+-------------------+-----------+----------+-------------
dummy | character varying | | extended |
View definition:
SELECT 'X'::character varying AS dummy; postgres=# select * from dual;
dummy
-------
X
(1 row) postgres=# select 1 from dual;
?column?
----------
1
(1 row) Oracle兼容 包列表:
在PostgreSQL里用schema+函数来实现。
postgres=# \dn
List of schemas
Name | Owner
--------------+----------
dbms_alert | postgres
dbms_assert | postgres
dbms_output | postgres
dbms_pipe | postgres
dbms_random | postgres
dbms_utility | postgres
madlib | postgres
oracle | postgres
plunit | postgres
plvchr | postgres
plvdate | postgres
plvlex | postgres
plvstr | postgres
plvsubst | postgres
public | postgres
utl_file | postgres
(16 rows) 例如dbms_alert包:
postgres=# \df dbms_alert.*
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+----------------+------------------+-------------------------------------------------------------------------------+---------
dbms_alert | _signal | void | name text, message text | normal
dbms_alert | defered_signal | trigger | | trigger
dbms_alert | register | void | name text | normal
dbms_alert | remove | void | name text | normal
dbms_alert | removeall | void | | normal
dbms_alert | set_defaults | void | sensitivity double precision | normal
dbms_alert | signal | void | _event text, _message text | normal
dbms_alert | waitany | record | OUT name text, OUT message text, OUT status integer, timeout double precision | normal
dbms_alert | waitone | record | name text, OUT message text, OUT status integer, timeout double precision | normal
(9 rows)
(转)PostgreSQL 兼容Oracle - orafce的更多相关文章
- Dapper完美兼容Oracle,执行存储过程,并返回结果集。
Dapper完美兼容Oracle,执行存储过程,并返回结果集. 这个问题,困扰了我整整两天. 刚刚用到Dapper的时候,感觉非常牛掰.特别是配合.net 4.0新特性dynamic,让我生成泛型集合 ...
- KingbaseES V8R6兼容Oracle的exp-imp导出导入工具使用
说明: KingbaseES V8R6版本中的兼容Oracle的exp-imp导入导出工具,支持完全模式.用户模式和表模式的导出功能. 本次案例数据库版本: test=# select version ...
- 采用Hibernate框架的研发平台如何能够真正兼容Oracle和sqlServer数据库
都说Hibernate框架的使用可以很容易的让你的研发平台支持多种不同类型的数据库,但实践表明,这里的“容易”,是相对的. 想让研发平台支持多种数据库,并不是一件简单的事,也可以这么说:并不是只要使用 ...
- postgresql和oracle数据库对比
SQL执行计划干预 从使用postgresql来看,想要改变执行计划只能通过対表进行分析,不能通过添加hint的方式来改变执行计划: oracle不仅可以通过对表进行收集统计来改变执行计划,而且很重要 ...
- SpringMVC,MyBatis项目中兼容Oracle和MySql的解决方案及其项目环境搭建配置、web项目中的单元测试写法、HttpClient调用post请求等案例
要搭建的项目的项目结构如下(使用的框架为:Spring.SpingMVC.MyBatis): 2.pom.xml中的配置如下(注意,本工程分为几个小的子工程,另外两个工程最终是jar包): 其中 ...
- SNF平台从sql server兼容oracle的处理方式和开发方式
前几天有这样一个需求,就是让SNF平台BS版的基础程序全面支持Oracle数据库. 初一看这是一个很大的工程,因为大家都知道 Sql和Oracle的语法有很多的不一样,如 top .日期获取.类型之间 ...
- postgresql与Oracle:空字符串与null
空字符串:两个单引号,中间无空格等任何内容 在postgresql中,空字符串与null是不同的:而oracle中,空字符串与null等同.测试如下: postgresql中: postgres=# ...
- PostgreSQL与Oracle对应的函数
一.对应的函数 1.sysdate oracle pgsql sysdate current_date. current_timestamp nvl coalesce trunc date_trun ...
- Windows的ODBC配置指南: MySQL, PostgreSQL, DB2, Oracle
MySQL- 官网: https://dev.mysql.com/downloads/connector/odbc/- 安装: * msi格式, 直接安装即可 * zip格式, 解压缩, 命令行(管理 ...
随机推荐
- mysql explain的使用(优化查询)
explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 1.创建数据库 创建的sql语句如下: /* Navicat MySQL D ...
- S5P4418开发板介绍
网站:http://topeetboard.com 1. 控制台(console)串口使用串口线连接开发板的 COM3到PC 机的串口,如果PC 或笔记本没有串口,就需要准备一条 USB 转串口的设备 ...
- Caffe源码解析5:Conv_Layer
转载请注明出处,楼燚(yì)航的blog,http://home.cnblogs.com/louyihang-loves-baiyan/ Vision_layer里面主要是包括了一些关于一些视觉上的操 ...
- POJ2828 Buy Tickets[树状数组第k小值 倒序]
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19012 Accepted: 9442 Desc ...
- POJ1190生日蛋糕[DFS 剪枝]
生日蛋糕 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18236 Accepted: 6497 Description ...
- NYOJ 762
容斥原理 http://blog.csdn.net/shiren_bod/article/details/5787722
- 第19章 集合框架(3)-Map接口
第19章 集合框架(3)-Map接口 1.Map接口概述 Map是一种映射关系,那么什么是映射关系呢? 映射的数学解释 设A,B是两个非空集合,如果存在一个法则,使得对A中的每一个元素a,按法则f,在 ...
- Django调用JS、CSS、图片等静态文件
zz 在下面的例子中,我们将media作为静态(CSS\JS\图片文件)文件的目录 方法一. 1.首先在settings.py文件中自定义参数 STATIC_PATH=’./media’ .(意为当前 ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 基于数据库资源的多语言实现
以前的开发平台里,是用xml语言包实现了多语言功能,现在新的平台里进行了调整,把多语言包资源放在数据库表里实现了. 我们系统预留了多语言的配置全局变量.可以通过配置这个参数达到切换多语言的目的 我们在 ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 员工离职管理
当公司有几万人,上千家加盟网点,几个庞大的直属分公司后,系统账户的有效管理也是一个头疼的问题,把所有的帐户及时进行科学的管理,有人员离职时及时进行记录,防止离职人员的系统账户有各种安全漏洞. 谁什么时 ...