【LightDB】Oracle存储过程兼容-函数兼容1
LightDB22.2之前的版本创建函数语法如下例子:
create or replace function func1(a int, b int)
returns int
as $$
declare
x int := 0;
begin
x := a + b;
raise info 'sum=%', x;
return x;
end;
$$ language plpgsql;
同样的函数Oracle定义如下:
create or replace function func1(a int, b int)
return int
is
x int := 0;
begin
x := a + b;
DBMS_OUTPUT.PUT_LINE('sum='||x);
return x;
end;
/
由上面例子可以看出,要兼容Oracle创建函数语法,要做出以下支持:
- 支持返回关键字return。
- 隐藏关键字declare。
- 支持关键字is。
- 支持Oracle匿名块。
目前LightDB 22.2版本已经支持Oracle创建函数语法,示例如下:
lightdb@postgres=# create or replace function func1(a int, b int)
lightdb@postgres-# return int
lightdb@postgres-# is
lightdb@postgres$# x int := 0;
lightdb@postgres$# begin
lightdb@postgres$# x := a + b;
lightdb@postgres$# DBMS_OUTPUT.PUT_LINE('sum='||x);
lightdb@postgres$# return x;
lightdb@postgres$# end;
lightdb@postgres$# /
CREATE FUNCTION
lightdb@postgres=# select func1(2, 3);
sum=5
func1
-------
5
(1 row)
lightdb@postgres=#
其中’DBMS_OUTPUT.PUT_LINE’函数由插件orafce实现,LightDB原生集成了插件orafce。
详细语法可参考LightDB官网查看https://www.hs.net/lightdb
更多请登录LightDB官网进行查看:https://www.hs.net/lightdb