Oracle 过程错误:预期 UDT 为 CHAR

问题描述 投票:0回答:1

使用 Oracle 19c,我正在尝试编写一个存储过程。 我已经删除了很多其他代码,但在最简单的形式中,我需要运行一些动态 SQL,然后返回记录中的值。 我运行时遇到的错误(编译正常)是:

ORA-00932: inconsistent datatypes: expected UDT got CHAR

我的代码是:

create or replace TYPE rep_mapping_object as OBJECT
  ( REGISTRY_ID varchar2(20 BYTE )
);

CREATE OR REPLACE TYPE rep_mapping_record IS TABLE OF rep_mapping_object;

create or replace PROCEDURE my_test( vROW OUT rep_mapping_record )
IS 
mySQL varchar2(2000); 
BEGIN

mySQL := 'select registry_id from src_territory_assignment fetch first row only';

execute immediate mySQL into vROW;
END;

当这个问题解决后,我的rep_mapping_object将有更多的列,SQL语句也将有更多的列。 SQL 语句将仅返回 0 或 1 行。

我做错了什么?

plsql oracle19c
1个回答
0
投票

具体方法如下:

样品类型及表格:

SQL> create or replace type rep_mapping_object as object
  2    ( registry_id varchar2(20 byte )
  3  );
  4  /

Type created.

SQL> create or replace type rep_mapping_record is table of rep_mapping_object;
  2  /

Type created.

SQL> create table src_territory_assignment as
  2    select 'USA' registry_id from dual union all
  3    select 'FRA'             from dual;

Table created.

程序;参见第 5 行和第 6 行:

SQL> create or replace procedure my_test( vrow out rep_mapping_record )
  2  is
  3    mysql varchar2(2000);
  4  begin
  5    mysql := 'select rep_mapping_object(registry_id) from src_territory_assignment fetch first row only';
  6    execute immediate mysql bulk collect into vrow;
  7  end;
  8  /

Procedure created.

测试:

SQL> set serveroutput on
SQL> declare
  2    l_result rep_mapping_record;
  3  begin
  4    my_test (l_result);
  5    dbms_output.put_line(l_result(1).registry_id);
  6  end;
  7  /
USA

PL/SQL procedure successfully completed.

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.