Question

I have created following package and then got error after running the provided sql. I created object type, table type, package.

Please help me.

CREATE TYPE ItemRec
 AS OBJECT
 (TABLE_NAME VARCHAR2(50),
    ISSUE      VARCHAR2(4000));
    /

CREATE TYPE ItemSet
IS
  TABLE OF ItemRec;
  /

CREATE OR REPLACE
PACKAGE PKG_REPL_DATA
AS
  FUNCTION FN_REPL_DELTA
    RETURN ItemSet;
END;
/
CREATE OR REPLACE
PACKAGE BODY PKG_REPL_DATA
AS
FUNCTION FN_REPL_DELTA
  RETURN ItemSet
AS
  v_items ItemSet;
  v_item_out ItemRec;
  v_list_out ItemSet;
BEGIN
  EXECUTE IMMEDIATE ' SELECT ''ABCD'', ''CUSTID: '' || 1 FROM DUAL' BULK COLLECT INTO v_items;
  RETURN v_items;
END;
END;
/

Following sql gives error.

SELECT * FROM TABLE(cast(pkg_repl_data.fn_repl_delta() AS ItemSet));

Error:

Error starting at line 43 in command:
SELECT * FROM TABLE(cast(pkg_repl_data.fn_repl_delta() AS ItemSet))
Error report:
SQL Error: ORA-00932: inconsistent datatypes: expected UDT got CHAR
ORA-06512: at "DSTBREPR3.PKG_REPL_DATA", line 10
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:
Was it helpful?

Solution

You'd need to select a single object type, not two separate varchar2 values. Something like

EXECUTE IMMEDIATE
  'SELECT ItemRec( ''ABCD'', ''CUSTID:'' ) FROM dual'
  BULK COLLECT INTO v_items;

In your code sample, there would be no reason to use dynamic SQL here, it's only complicating the code. Hopefully, there is an actual reason to use dynamic SQL in the actual code that you're building.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top