AntDB是基于PG内核国内自主研发的一款开源分布式数据库,兼容oracle语法。这里简单介绍一下使用oracle语法的三种方法。
第一种:服务器级别,修改数据库配置文件默认为oracle语法
通过集群管理工具设置语法
postgres=# set coordinator all(grammar = oracle);
SET PARAM
设置过后,会在相应coordinator的配置文件postgresql.conf中写“grammar = oracle”。此时可以直接执行oracle语法。
[shan2@localhost1 0]$ psql -d postgres -p 4335
psql (3.1devel 7b91fbb based on PG 9.6.2)
Type "help" for help.
postgres=# select months_between(to_date('2017-4-30','yyyy-mm-dd'),to_date('2017-3-30','yyyy-mm-dd')) from dual;
months_between
----------------
1
(1 row)
第二种:会话级别,设置session级别参数指定oracle语法
postgres=# set grammar to oracle;
SET
postgres=# select months_between(to_date('2017-4-30','yyyy-mm-dd'),to_date('2017-3-30','yyyy-mm-dd')) from dual;
months_between
----------------
1
(1 row)
对比:把会话级别参数修改到postgres,则不支持oracle语法。
postgres=# set grammar to postgres;
SET
postgres=# select months_between(to_date('2017-4-30','yyyy-mm-dd'),to_date('2017-3-30','yyyy-mm-dd')) from dual;
ERROR: function months_between(date, date) does not exist
LINE 1: select months_between(to_date('2017-4-30','yyyy-mm-dd'),to_d...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
postgres=#
第三种:语句级别, 通过/*ora*/或/*oracle*/等前缀注释指定按Oracle语法执行SQL
postgres=# /*ora*/ select months_between(to_date('2017-4-30','yyyy-mm-dd'),to_date('2017-3-30','yyyy-mm-dd')) from dual;
months_between
----------------
1
(1 row)
目前,ADB支持大部分常用oracle函数的语法,上面只是以months_between函数为例说明。下面的表格是ADB与Oracle的功能对比。
关于AntDB的具体信息,请见下面的链接。
代码地址:
QQ交流群:496464280