Greenplum的Oracle兼容性函数

来源:互联网 发布:现在卖域名还赚钱吗 编辑:程序博客网 时间:2024/05/07 12:14
许多Oracle的SQL函数可以应用到Greenplum数据库中。Greenplum默认安装完成后并不能使用Oracle的兼容性函数。
template1=# select nvl(null,2);
ERROR:  function nvl(unknown, integer) does not exist
LINE 1: select nvl(null,2);


在使用任何Oracle兼容函数之前,你必须为每个数据库执行下面的安装脚本(示例为testdb数据库):
psql -d testdb -f $GPHOME/share/postgresql/contrib/orafunc.sql


当然你也可以卸载Oracle函数:
psql -d testdb -f $GPHOME/share/postgresql/contrib/uninstall_orafunc.sql


安装完成后,如果直接在testdb数据库中使用还会找不到Oracle的相关函数,比如:
testdb=# select nvl(null,8);
ERROR:  function nvl(unknown, integer) does not exist
LINE 1: select nvl(null,8);
               ^
HINT:  No function matches the given name and argument types. You may need to add explicit type casts.


我们查看schema是搜索路径:
testdb=# show search_path ;
  search_path   
----------------
 "$user",public


Oracle的兼容函数都安装在oracompat的schema下面。为了访问这些Oracle函数,可以指定oracompat前缀或者修改数据库的搜索路径:
ALTER DATABASE testdb SET search_path = "$user", public, oracompat;


然后重新登录Greenplum环境:
[gpadmin@cdha postgresql]$ psql -d testdb
psql (8.2.15)
Type "help" for help.


testdb=# select nvl(null,8);
 nvl 
-----
   8


可以看到Greenplum中可以正常使用Oracle的兼容函数了。



0 0
原创粉丝点击