PLSQ存储过程编译提示“没有足够的值”,

Shawlj 2018-04-16 04:09:11

问题是这样的,程序定义了自定义Table对象,将查询的结果集保存到Table对象中返回,
通过测试发现值的个数是对应上的。也就说不存在值个数不足的问题

网友有的说字段类型不匹配也会有这个提示,如何进行转换或者避免呢
...全文
721 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Shawlj 2018-04-17
  • 打赏
  • 举报
回复
引用 11 楼 wmxcn2000 的回复:
[quote=引用 10 楼 u012411219 的回复:] [quote=引用 9 楼 wmxcn2000 的回复:] select t_bill_detail_nc ( 改成 o_bill_detail  PS:我给你写的例子,你仔细看一下。
编译通过了,但是我要的多行记录。不是单行。[/quote] 加这个     bulk collect PS:4 楼给你写例子了,还算详细。 [/quote] 感谢版主,顺便请教下,后续步骤因为需要将这个结果集存储到具体TABLE表中,比如:

第一步全部放入my_table表:insert into my_table values(t_bill_detail_nc)?
第二步遍历 t_bill_detail_nc 表对象数据,取出bill_detail_id去更新t_wh_bill_detail表中字段的状态。
Shawlj 2018-04-17
  • 打赏
  • 举报
回复
引用 11 楼 wmxcn2000 的回复:
[quote=引用 10 楼 u012411219 的回复:] [quote=引用 9 楼 wmxcn2000 的回复:] select t_bill_detail_nc ( 改成 o_bill_detail  PS:我给你写的例子,你仔细看一下。
编译通过了,但是我要的多行记录。不是单行。[/quote] 加这个     bulk collect PS:4 楼给你写例子了,还算详细。 [/quote] 我才看到bulk collect ,( ╯□╰ ),
卖水果的net 2018-04-17
  • 打赏
  • 举报
回复
引用 10 楼 u012411219 的回复:
[quote=引用 9 楼 wmxcn2000 的回复:] select t_bill_detail_nc ( 改成 o_bill_detail  PS:我给你写的例子,你仔细看一下。
编译通过了,但是我要的多行记录。不是单行。[/quote] 加这个     bulk collect PS:4 楼给你写例子了,还算详细。
卖水果的net 2018-04-17
  • 打赏
  • 举报
回复
select t_bill_detail_nc ( 改成 o_bill_detail  PS:我给你写的例子,你仔细看一下。
Shawlj 2018-04-17
  • 打赏
  • 举报
回复
引用 9 楼 wmxcn2000 的回复:
select t_bill_detail_nc ( 改成 o_bill_detail  PS:我给你写的例子,你仔细看一下。
编译通过了,但是我要的多行记录。不是单行。
Shawlj 2018-04-17
  • 打赏
  • 举报
回复
引用 6 楼 wmxcn2000 的回复:
贴完整代码,不要图片。
自定义对象:
create or replace type o_bill_detail as object
(
  bill_detail_id number, --业务单据明细ID
  trans_type_id number, -- 业务单据类型ID
  trans_type_code varchar2(20), -- 业务单据类型编码
  trans_type_name varchar2(50), -- 业务单据类型名称
  item_id number, -- 物料ID
  warehouse_id number, -- 仓库ID
  nc_batch_code varchar2(50), -- 批次
  nc_dispatcher_id varchar2(50), -- NC单据编码
  supplier_id number, -- 供应商ID
  nc_norgnet_tax_price float, -- NC价格
  nc_number number, -- 数量
  nc_inventory_code varchar2(100), -- NC存货编码
  nc_warehouse_id varchar2(50), -- NC仓库编码
  nc_whether_batch varchar2(2), -- NC是否批次管理
  nc_supplier varchar2(50), -- NC供应商编码
  mes_uuid varchar2(50), -- MES唯一码
  mes_date varchar2(25) -- MES同步日期
)
--自定义table对象
create or replace type t_bill_detail_nc is table of o_bill_detail
--测试脚本
function bills_cgrk_syn_list(p_req_purchaser in varchar2) return t_bill_detail_nc is
    bill_detail_nc_tab t_bill_detail_nc; --自定义表对象类型
    
    bill_detail_nc_o o_bill_detail; --自定义表对象类型    
  begin
     --select t_bill_detail_nc(rs.*) into bill_detail_nc_tab from   (
      select t_bill_detail_nc (
             tb.bill_detail_id,

             tb.trans_type_id,
             tb.trans_type_code,
             tb.trans_type_name,
             tb.item_id,
             tb.warehouse_id,
             tb.nc_batch_code,
             tb.nc_dispatcher_id,
             tb.supplier_id,
             tb.nc_norgnet_tax_price,
             tb.nc_number,
             t3.nc_item_code,
             t5.interface_code,
             decode(nvl(t4.islot, '0'), '1', 'Y', 'N') ,
             t6.interface_code,
             sys_guid(),
             to_char(sysdate,'yyyy-mm-dd HH24:mi:ss'))
        into bill_detail_nc_tab
        from (select t2.bill_detail_id,
                     t1.trans_type_id,
                     t1.trans_type_code,
                     t1.trans_type_name,
                     t2.item_id,
                     t2.wh_id as warehouse_id,
                     t2.lot as nc_batch_code,
                     t1.interface_code  as nc_dispatcher_id,
                     t.supplier_id,
                     td.price as nc_norgnet_tax_price,
                     t2.act_receive_qty as nc_number
                from t_wh_bill t
                left join t_wh_trans_bill_type t1
                  on t.trans_type_id = t1.trans_type_id
                left join t_wh_bill_detail t2
                  on t2.bill_id = t.bill_id
                left join t_po_order_detail td
                  on t2.po_order_detail_id = td.order_detail_id
               where t2.bill_status = '1'
                 and nvl(t2.nc_status, 0) = '0'
                 and t2.mes_sid is null
                 and t.bill_date >= '2018-03-01'
                 and t.bill_date <= '2018-03-07'
                 and instr(t1.trans_type_code, C_CGRK_CODE) > 0) tb
        left join t_basic_item t3
          on tb.item_id = t3.item_id
        left join t_basic_item_logistics t4
          on tb.item_id = t4.item_id
        left join t_wh_info t5
          on tb.warehouse_id = t5.wh_id
        left join t_basic_supplier t6
          on t6.supplier_id = tb.supplier_id;
    return bill_detail_nc_tab;
  end bills_cgrk_syn_list;
Shawlj 2018-04-17
  • 打赏
  • 举报
回复
现在是这个错误了, 错误:PL/SQL: ORA-00932: 数据类型不一致: 应为 UDT, 但却获得 NUMBER,
卖水果的net 2018-04-16
  • 打赏
  • 举报
回复
贴完整代码,不要图片。
Shawlj 2018-04-16
  • 打赏
  • 举报
回复
加了这个type转换提示 错误:PL/SQL: ORA-01747: user.table.column, table.column 或列说明无效
卖水果的net 2018-04-16
  • 打赏
  • 举报
回复

-- 给你写个例子

SQL> 
SQL> create type t_type as object(
  2    id int,
  3    name varchar(10),
  4    remark varchar(10)
  5  );
  6  /
Type created
SQL> create type tt_type is table of t_type;
  2  /
Type created
SQL> create or replace function fn(p varchar2) return tt_type is
  2    v_tt_type tt_type;
  3  begin
  4    select t_type(100, p, 'remark')
  5      bulk collect
  6      into v_tt_type
  7      from user_objects
  8     where rownum <= 5;
  9    return v_tt_type;
 10  end;
 11  /
Function created
SQL> set serverout on;
SQL> declare
  2    result tt_type;
  3  begin
  4    result := fn('dddddd');
  5    dbms_output.put_line('count = ' || result.count);
  6  end;
  7  /
count = 5
PL/SQL procedure successfully completed
SQL> drop type tt_type;
Type dropped
SQL> drop type t_type;
Type dropped
SQL> drop function fn;
Function dropped

SQL> 
Shawlj 2018-04-16
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:
猜不出来,贴代码吧;
为什么我不能编辑我的帖子了
Shawlj 2018-04-16
  • 打赏
  • 举报
回复
卖水果的net 2018-04-16
  • 打赏
  • 举报
回复
猜不出来,贴代码吧;

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧