許多Oracle的SQL函數(shù)可以應用到Greenplum數(shù)據(jù)庫中。Greenplum默認安裝完成后并不能使用Oracle的兼容性函數(shù)。
template1=# select nvl(null,2);
ERROR: function nvl(unknown, integer) does not exist
LINE 1: select nvl(null,2);
在使用任何Oracle兼容函數(shù)之前,你必須為每個數(shù)據(jù)庫執(zhí)行下面的安裝腳本(示例為testdb數(shù)據(jù)庫):
psql -d testdb -f $GPHOME/share/postgresql/contrib/orafunc.sql
當然你也可以卸載Oracle函數(shù):
psql -d testdb -f $GPHOME/share/postgresql/contrib/uninstall_orafunc.sql
安裝完成后,如果直接在testdb數(shù)據(jù)庫中使用還會找不到Oracle的相關(guān)函數(shù),比如:
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的兼容函數(shù)都安裝在oracompat的schema下面。為了訪問這些Oracle函數(shù),可以指定oracompat前綴或者修改數(shù)據(jù)庫的搜索路徑:
ALTER DATABASE testdb SET search_path = "$user", public, oracompat;
然后重新登錄Greenplum環(huán)境:
[gpadmin@cdha postgresql]$ psql -d testdb
psql (8.2.15)
Type "help" for help.
testdb=# select nvl(null,8);
nvl
-----
8
可以看到Greenplum中可以正常使用Oracle的兼容函數(shù)了。