【问题标题】:Oracle 19C database issueOracle 19C 数据库问题
【发布时间】:2020-05-30 04:35:10
【问题描述】:

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

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

PFB 描述。

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

使用带有表子句的函数

select * from table(function)

这样返回值可以充当表格,我可以读取带有列名的结果。

在 11g 中,该函数返回与游标列名称相同的列标题。 但在 19c 中,该函数返回列标题,如“Attr_1、Attr_2 等”。

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

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

示例: 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 roe(l_tab(i)); 
        end loop; 
    return ; 
    end; 
end pkg_test;


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

在 11g 中,上面的选择将列标题作为“id,描述”,但在 19c 中,我得到的是“ATTR_1,ATTR_2”。

请帮忙。

【问题讨论】:

标签: plsql cursor pipelined-function oracle19c


【解决方案1】:

您的问题的解决方案可能是:

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 {tb_test}%rowtype; 
    function fn_test(p_rows in number) return typ_cur_test pipelined; 
end;
  1. 能够重现解释的行为。在 19c -> Attr_1,在 11 上的 Attr_2 -> ID,描述

  2. 我发现的解决方法是使用base table/view%rowtype 而不是cursor%rowtype

【讨论】:

  • 我没有发现我的包规范和你的代码有任何区别。添加 { 以区分。没有别的。
  • 对于我的代码中存在的每个光标,我无法创建视图权限。为什么行为在 19C 中发生了变化?有什么办法可以在新版本中恢复 11g 的行为?
  • 可能支持可以在这里为您提供帮助。也许如果你改变兼容模式。
  • 来自 Ask Tom 的 Connor McDonald 通知我向 Oracle 团队提出请求,因为这是一个错误。 asktom.oracle.com/pls/apex/…
猜你喜欢
  • 2022-01-19
  • 2021-01-05
  • 2021-01-16
  • 1970-01-01
  • 2022-01-20
  • 2021-10-20
  • 2021-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多