Skip to content
Advertisement

Why do I get this Error: ORA-00932: inconsistent datatypes: expected – got –

I am trying to cast a number to a varchar with the CAST function in order to be able to concatenate inside dbms_output.put_line().

Please note that you need to be able to understand collection types in Oracle PL-SQL to be able to understand my code.

Please see below code:

If my logic is correct I must see a string like this one “Index counter: 1” print out for me.

Advertisement

Answer

Guessing at your problem specification, there seem to be two problems in your code.

First, you define an object type and a nested table type – as nested table of objects. Your table column data type is not the object type you defined, but the collection of such objects (the nested table type). Finally, you define orders_va as a variable array of objects, and you attempt to collect values from the table column into this array. This is the first problem: the column values are not individual objects, they are collections of objects. If you want to collect them into the orders_va array, then the array must be an array of nested tables of objects, not an array of individual objects.

After you make this change, in the anonymous block you will not be able to reference the order_id member of an element of the array – because the array elements are nested tables of objects, they are not individual objects. To access the object members, you will need to loop over nested table elements (within the outer loop over array elements).

The two changes are in the definition of orders_va and the loop in the anonymous block.

Note that empt_t is an array of nested tables of objects; empt_t(i) is one of those nested tables, and empt_t(i)(j) is the j’th object in the nested table. i corresponds to rows in your table; j corresponds to individual objects in the nested table which is an atomic value in your table column (in row i).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement