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

Oracle 19C数据库问题与表类型和流水线

ASKTOM 2020-02-14
605

问题描述

我有一个在11g版本中运行良好的软件包。

但是当我在19c版本中部署相同的软件包时,行为是不同的。

PFB的描述。

包规范具有游标,并创建了具有游标 % rowtype的表类型。具有返回表类型的流水线函数。

使用带有table子句的函数

从表中选择 * (函数)
以便返回值可以充当表,并且我可以使用列名读取结果。

在11g中,该函数返回与游标列名相同的列标题。但是在19c中,函数正在返回类似 'attr_1,Attr_2,etc' 的列标题。

我需要函数将列标题作为光标列名称返回。

注意: 代码不能共享,因为它非常敏感。

样品: PFB样品。
Create table tb_test (id number, description varchar2 (50));  

create or replace package pkg_test is 
    cursor cur_test is 
        select * 
        from tb_test 
        where 1=2; 
    type typ_cur_test is table of cur_test%rowtype; 
    function fn_test(p_rows in number) return typ_cur_test pipelined; 
end;

create or replace package body pkg_test is 
    function fn_test(p_rows in number) return typ_cur_test pipelined as 
    l_tab typ_cur_test := cur_typ_test(); 
    begin 
        for i in 1..p_rows loop l_tab.extend; 
            l_tab(i).Id := i; 
            l_tab(i). Description := 'test'; 
            pipe row(l_tab(i)); 
        end loop; 
    return ; 
    end; 
end pkg_test;


Select * from table(pkg_test.fn_test(2));
In 11g, the above select gives column headers as "id, description", but in 19c i am getting as "ATTR_1, ATTR_2".


请帮忙。

Stackover流程:https://stackoverflow.com/questions/60225275/oracle-19c-database-issue

专家解答

我也在18号上复制了你的结果。这是一个错误-请在支持下记录它 (如果它来自客户,它会比我这样做的优先级更高)。

SQL> Create table tb_test (id number, description varchar2 (50));

Table created.

SQL>
SQL> create or replace package pkg_test is
  2      cursor cur_test is
  3          select *
  4          from tb_test
  5          where 1=2;
  6      type typ_cur_test is table of cur_test%rowtype;
  7      function fn_test(p_rows in number) return typ_cur_test pipelined;
  8  end;
  9  /

Package created.

SQL> create or replace package body pkg_test is
  2      function fn_test(p_rows in number) return typ_cur_test pipelined as
  3      l_tab typ_cur_test := typ_cur_test();
  4      begin
  5          for i in 1..p_rows loop l_tab.extend;
  6              l_tab(i).Id := i;
  7              l_tab(i). Description := 'test';
  8              pipe row(l_tab(i));
  9          end loop;
 10      return ;
 11      end;
 12  end pkg_test;
 13  /

Package body created.

SQL> Select * from table(pkg_test.fn_test(2));

    ATTR_1 ATTR_2
---------- --------------------------------------------------
         1 test
         2 test

2 rows selected.


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

评论