暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle中的sql%rowcount在瀚高数据库中的兼容方案

瀚高PG实验室 2022-05-07
824

目录

环境

症状

问题原因

解决方案

环境

系统平台:Linux x86-64 Red Hat Enterprise Linux 7

版本:4.5

症状

Oracle的函数迁移到瀚高数据库,应用程序调用瀚高数据库的函数时,提示“com.highgo.jdbc.util.PSQLException:错误: 字段 "sql" 不存在”的错误。

问题原因

经调查,在Oracle中使用了sql%rowcount,获取更新或者删除语句的修改行数。

该语法在瀚高数据库中不兼容,需要单独修改。

解决方案

在瀚高数据库中使用get diagnostics rowcnt := row_count;语句替代sql%rowcount,同样也是获取更新或者删除语句的修改行数。

示例如下:

Oracle:

    create table t1(id numeric,sname varchar(10),primary key(id));

    create or replace function testfnc return number

    as

    n number;

    begin

    insert into t1 values(1,'zhao');

    n:=sql%rowcount;

    commit;

    dbms_output.put_line(n);

    return 0;

    end;

    (左右滑动查看完整内容)

    执行函数后,输出行数是1测试结果:

    检索t1表的数据,插入了1条记录

    瀚高:

      create table t1(id numeric,sname varchar(10),primary key(id));

      create or replace function testfnc() returns numeric

      language plpgsql

      as

      $body$

      declare

      n numeric;

      begin

      insert into t1 values(1,'zhao');

      --n:=sql%rowcount;

      get diagnostics n := row_count;

      raise notice '%',n;

      return 0;

      end;

      $body$

      (左右滑动查看完整内容)

      执行函数后,输出行数是1测试结果:

      检索t1表的数据,插入了1条记录


      文章转载自瀚高PG实验室,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

      评论