LightDB 23.3支持dbms_output.new_line函数

开篇立意

oracle支持dbms_output.new_line函数,调用时不加括号和参数,如下图所示:
1
从图中我们能够看出:
(1)hs_func创建时可以不带参数进行创建;
(2)创建之后的函数可以使用两种方式进行调用。
如果在创建函数时加上括号,哪调用时不加括号能创建成功吗?
SQL> create function hs_func_q() return int as
2 begin
3 return 1;
4 end;
5 /

Warning: Function created with compilation errors.
.函数创建失败,必须要带参数进行创建。
SQL> create function hs_func_q(i int) return int as
2 begin
3 return 1;
4 end;
5 /

Function created.

解决方案

语法层能使该语法正确执行
lightdb@test_createdb_oracle=# create function hs_func return int as
lightdb@test_createdb_oracleKaTeX parse error: Expected 'EOF', got '#' at position 1: #̲ begin lightd…# return 12;
lightdb@test_createdb_oracleKaTeX parse error: Expected 'EOF', got '#' at position 1: #̲ end; lightdb…# /
CREATE FUNCTION
调用时需要注意,创建的函数如果需要不加括号调用,需要加上模式名才能识别,这块没动LightDB内核。考虑是否在下个版本改动。
oracle 函数函数时如果是()不加参数,会报错。但是LightDB内核是兼容这中写法的。即:
lightdb@test_createdb_oracle=# \sf hs_func_q
CREATE OR REPLACE FUNCTION public.hs_func_q()
RETURNS integer
LANGUAGE plorasql
AS f u n c t i o n function function
begin
return 12;
end; f u n c t i o n function function
这块不能完全因为兼容oracle去掉这个语法。因为兼容oracle只是LightDB兼容三部曲中的一部,还有保证PG本身的逻辑不被改变。
并且创建hs_func 之后不允许创建hs_func().
lightdb@test_createdb_oracle=# CREATE FUNCTION public.hs_func
RETURNS integer
LANGUAGE plorasql
AS f u n c t i o n function function
begin
return 12;
end; f u n c t i o n function function;
CREATE FUNCTION
lightdb@test_createdb_oracle=# CREATE FUNCTION public.hs_func()
RETURNS integer
LANGUAGE plorasql
AS f u n c t i o n function function
begin
return 12;
end; f u n c t i o n function function;
ERROR: function “hs_func” already exists with same argument types
原因是这两种创建方式创建出来的函数是同一个函数。
那是不是可以使用兼容性参数进行隔离,答案也是不可以的。因为LightDB数据库除了本身之外,还有插件,如果进行了限制,插件由于独立性,不能指定兼容模式,因此这个功能就不能使用。

lt_dump导致的数据备份问题

由于创建的函数hs_func 和hs_func()本身就是一个函数,备份时,会将hs_func 转换成hs_func()

Name: hs_func_q(); Type: FUNCTION; Schema: public; Owner: lightdb
CREATE FUNCTION public.hs_func_q() RETURNS integer
LANGUAGE plorasql
AS b e g i n r e t u r n 12 ; e n d ; begin return 12; end; beginreturn12;end;;
调用方式相同。都需要加上模式名。思来想去,这个东西是必要的,不然就会存在大量的字段不能跟函数名重名。改动较好的就是先找字段名,找不到再来匹配函数。这样肯定会影响效率的,需要进行评审的。

测试

正常测试用例

lightdb@test_createdb_oracle=# select dbms_output.serveroutput(true);
serveroutput

(1 row)

lightdb@test_createdb_oracle=#
lightdb@test_createdb_oracle=# select dbms_output.new_line;

new_line

(1 row)

lightdb@test_createdb_oracle=# select dbms_output.new_line();

new_line

(1 row)

lightdb@test_createdb_oracle=#
lightdb@test_createdb_oracle=# do
lightdb@test_createdb_oracle-# KaTeX parse error: Can't use function '$' in math mode at position 30: …createdb_oracle$̲# begin … language plpgsql;
a

d
DO

预期出错

lightdb@test_createdb_oracle=# --error
lightdb@test_createdb_oracle=# select dbms_output.new_line(12);
ERROR: function dbms_output.new_line(integer) does not exist
LINE 1: select dbms_output.new_line(12);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_createdb_oracle=# select dbms_output.new_line(‘try’);
ERROR: function dbms_output.new_line(unknown) does not exist
LINE 1: select dbms_output.new_line(‘try’);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_createdb_oracle=# select dbms_output.new_line(true);
ERROR: function dbms_output.new_line(boolean) does not exist
LINE 1: select dbms_output.new_line(true);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_createdb_oracle=# select dbms_output.new_line(true,12);
ERROR: function dbms_output.new_line(boolean, integer) does not exist
LINE 1: select dbms_output.new_line(true,12);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

总结

(1)LightDB 23.3支持dbms_out.new_line函数其实是增加了一种创建函数的方式,不用加括号,函数也能创建成功。
(2)并且加括号和不加括号创建的函数其实在内核中是同一个函数。
(3)使用一种创建方式另外一种就不可使用,使用会报错。
(4)数据迁移备份不会有问题。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值