RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1269399
Accepted
Alex Konkin
Alex Konkin
Asked:2022-04-13 03:05:30 +0000 UTC2022-04-13 03:05:30 +0000 UTC 2022-04-13 03:05:30 +0000 UTC

创建 piplined 函数时出错:PLS-00321:表达式 <数据类型> 不适合作为赋值语句的左侧

  • 772

我有一个包含以下示例数据的表:

with t as (
select 123456 DRAW_KEY, 1 WINCAT_NUM,0 WIN_AMOUNT,0 WIN_COUNT
from dual
union all
select 123456 DRAW_KEY, 2 WINCAT_NUM,0 WIN_AMOUNT,0 WIN_COUNT
from dual
union all
select 123456 DRAW_KEY, 3 WINCAT_NUM,0 WIN_AMOUNT,0 WIN_COUNT
from dual
union all
select 123456 DRAW_KEY, 4 WINCAT_NUM,30000 WIN_AMOUNT,12 WIN_COUNT
from dual
union all
select 123456 DRAW_KEY, 5 WINCAT_NUM,6000 WIN_AMOUNT,73 WIN_COUNT
from dual
) select * from t

基于这些数据,我创建了一个piplined函数:

CREATE TYPE l_result AS OBJECT (
  DRAW_KEY number,
  WINCAT_NUM  number,
  WIN_AMOUNT number,
  WIN_COUNT number);
/
CREATE TYPE table_pip IS TABLE OF l_result;

CREATE FUNCTION MyFunction1(v_draw_key in number) RETURN table_pip Pipelined IS
  v_query clob;
  v_cols clob;
BEGIN
  select listagg(wincat_num ,', ') within group (order by wincat_num)
  into v_cols
  from customers1
  where draw_key = 123456; --v_draw_key!
  v_query := 'SELECT * FROM (
    select draw_key,wincat_num,win_amount,win_count
    from customers1
    where draw_key = 123456) PIVOT (
      sum(win_count) as win_count,sum(win_amount) as win_amount
      FOR wincat_num IN ('||v_cols||'))';
  EXECUTE IMMEDIATE v_query into l_result;
  pipe row(l_result);
END;

但它给出了错误:

PLS-00321:表达式“L_RESULT”不适合作为赋值语句的左侧

和

PLS-00306:调用“L_RESULT”时参数的数量或类型错误。

我写错了什么,请告诉我?

функции
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    0xdb
    2022-04-13T06:10:25Z2022-04-13T06:10:25Z

    原因: pipe row(l_result);,这里期望的是对象的实体,而不是对象类型本身。

    使用问题中的数据查看它如何与可重现的示例一起使用:

    create type resultRow as object (
        draw_key number, wincat_num  number, win_amount number, win_count number)
    /
    create type resultRows is table of resultRow
    /
    create or replace function pipefunc (draw_key in number) return resultRows pipelined is
    begin
        for r in (
            select * 
            from customers1 
            where draw_key = pipefunc.draw_key
        ) loop
            pipe row (resultRow (r.draw_key, r.wincat_num, r.win_amount, r.win_count));
        end loop;
        return;
    end;
    /
    

    调用和结果:

    select * from pipefunc (123456)
    /
    
      DRAW_KEY WINCAT_NUM WIN_AMOUNT  WIN_COUNT
    ---------- ---------- ---------- ----------
        123456          1          0          0
        123456          2          0          0
        123456          3          0          0
        123456          4      30000         12
        123456          5       6000         73
    

    PS
    此答案未涵盖函数中的动态请求,因为它与问题无关。请参阅使用动态列计数转置的相关主题。

    • 3

相关问题

  • 播放器控制锁(GDScript)[关闭]

  • 前 N 个元素的子列表

  • 相同输入的不同行为

  • 该过程返回一个空矩阵

  • = function () {} 是什么意思?

  • Haskell:是否可以将长度为 n 的列表的元素应用于函数?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5